mirror of
https://github.com/astral-sh/uv.git
synced 2025-11-18 19:21:46 +00:00
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:
parent
3e86c80874
commit
067acfe79e
8 changed files with 194 additions and 109 deletions
|
|
@ -105,17 +105,17 @@ impl<'a, Context: BuildContext + Send + Sync> ResolverProvider
|
|||
self.flat_index.get(package_name).cloned(),
|
||||
self.no_binary,
|
||||
)),
|
||||
Err(
|
||||
err @ (puffin_client::Error::PackageNotFound(_)
|
||||
| puffin_client::Error::NoIndex(_)),
|
||||
) => {
|
||||
if let Some(flat_index) = self.flat_index.get(package_name).cloned() {
|
||||
Ok(VersionMap::from(flat_index))
|
||||
} else {
|
||||
Err(err)
|
||||
Err(err) => match err.into_kind() {
|
||||
kind @ (puffin_client::ErrorKind::PackageNotFound(_)
|
||||
| puffin_client::ErrorKind::NoIndex(_)) => {
|
||||
if let Some(flat_index) = self.flat_index.get(package_name).cloned() {
|
||||
Ok(VersionMap::from(flat_index))
|
||||
} else {
|
||||
Err(kind.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => Err(err),
|
||||
kind => Err(kind.into()),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue