puffin-client: rejigger error type (#1102)

This PR changes the error type to be boxed internally so that it uses
less size on the stack. This makes functions returning `Result<T,
Error>`, in particular, return something much smaller.

The specific thing that motivated this was Clippy lints firing when I
tried to refactor code in this crate.

I chose to achieve boxing by splitting the enum out into a separate
type, and then wiring up the necessary `From` impl to make error
conversions easy, and then making `Error` itself opaque. We could expose
the `Box`, but there isn't a ton of benefit in doing so because one
cannot pattern match through a `Box`.

This required using more explicit error conversions in several places.
And as a result, I was able to remove all `#[from]` attributes on
non-transparent error variants.
This commit is contained in:
Andrew Gallant 2024-01-25 13:13:21 -05:00 committed by GitHub
parent 3e86c80874
commit 067acfe79e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 194 additions and 109 deletions

View file

@ -754,17 +754,17 @@ impl<'a, T: BuildContext> SourceDistCachedBuilder<'a, T> {
// Create a temporary directory.
let temp_dir = tempfile::tempdir_in(self.build_context.cache().root())
.map_err(puffin_client::Error::CacheWrite)?;
.map_err(puffin_client::ErrorKind::CacheWrite)?;
// Download the source distribution to a temporary file.
let mut writer = tokio::io::BufWriter::new(
fs_err::tokio::File::create(temp_dir.path().join(source_dist_filename))
.await
.map_err(puffin_client::Error::CacheWrite)?,
.map_err(puffin_client::ErrorKind::CacheWrite)?,
);
tokio::io::copy(&mut reader, &mut writer)
.await
.map_err(puffin_client::Error::CacheWrite)?;
.map_err(puffin_client::ErrorKind::CacheWrite)?;
Ok(temp_dir)
}