Review: Separate error types

This commit is contained in:
konstin 2025-10-27 11:23:53 +01:00
parent 05b3e8f3f4
commit 43b7eb76b6
5 changed files with 24 additions and 23 deletions

View File

@ -266,16 +266,19 @@ pub enum ErrorKind {
#[error("{0} isn't available locally, but making network requests to registries was banned")]
NoIndex(String),
/// The package was not found in the registry.
/// The package was not found in the registry (HTTP Error 404).
///
/// Make sure the package name is spelled correctly and that you've
/// configured the right registry to fetch it from.
#[error("Package `{package_name}` was not found in the registry")]
PackageNotFound {
package_name: String,
/// Not mentioned in the message, there's a separate hint with the details.
status_code_error: bool,
},
#[error("Package `{0}` was not found in the registry")]
PackageNotFound(PackageName),
/// The package was not found in the registry (HTTP Error 401 or 403).
///
/// Make sure the package name is spelled correctly and that you've
/// configured the right registry to fetch it from.
#[error("Package `{0}` was not found in the registry")]
StatusCodeError(PackageName),
/// The package was not found in the local (file-based) index.
#[error("Package `{0}` was not found in the local index")]

View File

@ -421,11 +421,13 @@ impl RegistryClient {
if results.is_empty() {
return match self.connectivity {
Connectivity::Online => Err(ErrorKind::PackageNotFound {
package_name: package_name.to_string(),
status_code_error: any_status_code_error.load(Ordering::Relaxed),
Connectivity::Online => {
if any_status_code_error.load(Ordering::Relaxed) {
Err(ErrorKind::StatusCodeError(package_name.clone()).into())
} else {
Err(ErrorKind::PackageNotFound(package_name.clone()).into())
}
}
.into()),
Connectivity::Offline => Err(ErrorKind::Offline(package_name.to_string()).into()),
};
}

View File

@ -556,20 +556,14 @@ pub async fn check_url(
Ok(response) => response,
Err(err) => {
return match err.kind() {
uv_client::ErrorKind::PackageNotFound {
status_code_error: false,
..
} => {
uv_client::ErrorKind::PackageNotFound(_) => {
// The package doesn't exist, it's the first upload of the package.
warn!(
"Package not found in the registry; skipping upload check for {filename}"
);
Ok(false)
}
uv_client::ErrorKind::PackageNotFound {
status_code_error: true,
..
} => {
uv_client::ErrorKind::StatusCodeError(_) => {
// The package may or may not exist, there was an authentication failure.
// TODO(konsti): We should show the real index error instead.
let status_code_detail = if index_capabilities.unauthorized(index_url) {

View File

@ -200,7 +200,8 @@ impl<Context: BuildContext> ResolverProvider for DefaultResolverProvider<'_, Con
.collect(),
)),
Err(err) => match err.kind() {
uv_client::ErrorKind::PackageNotFound { .. } => {
uv_client::ErrorKind::PackageNotFound(_)
| uv_client::ErrorKind::StatusCodeError(_) => {
if let Some(flat_index) = flat_index
.and_then(|flat_index| flat_index.get(package_name))
.cloned()

View File

@ -46,9 +46,10 @@ impl LatestClient<'_> {
Ok(archives) => archives,
Err(err) => {
return match err.kind() {
uv_client::ErrorKind::PackageNotFound { .. } => Ok(None),
uv_client::ErrorKind::NoIndex(_) => Ok(None),
uv_client::ErrorKind::Offline(_) => Ok(None),
uv_client::ErrorKind::PackageNotFound(_)
| uv_client::ErrorKind::StatusCodeError(_)
| uv_client::ErrorKind::NoIndex(_)
| uv_client::ErrorKind::Offline(_) => Ok(None),
_ => Err(err),
};
}