mirror of https://github.com/astral-sh/uv
Review: Separate error types
This commit is contained in:
parent
05b3e8f3f4
commit
43b7eb76b6
|
|
@ -266,16 +266,19 @@ pub enum ErrorKind {
|
||||||
#[error("{0} isn't available locally, but making network requests to registries was banned")]
|
#[error("{0} isn't available locally, but making network requests to registries was banned")]
|
||||||
NoIndex(String),
|
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
|
/// Make sure the package name is spelled correctly and that you've
|
||||||
/// configured the right registry to fetch it from.
|
/// configured the right registry to fetch it from.
|
||||||
#[error("Package `{package_name}` was not found in the registry")]
|
#[error("Package `{0}` was not found in the registry")]
|
||||||
PackageNotFound {
|
PackageNotFound(PackageName),
|
||||||
package_name: String,
|
|
||||||
/// Not mentioned in the message, there's a separate hint with the details.
|
/// The package was not found in the registry (HTTP Error 401 or 403).
|
||||||
status_code_error: bool,
|
///
|
||||||
},
|
/// 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.
|
/// The package was not found in the local (file-based) index.
|
||||||
#[error("Package `{0}` was not found in the local index")]
|
#[error("Package `{0}` was not found in the local index")]
|
||||||
|
|
|
||||||
|
|
@ -421,11 +421,13 @@ impl RegistryClient {
|
||||||
|
|
||||||
if results.is_empty() {
|
if results.is_empty() {
|
||||||
return match self.connectivity {
|
return match self.connectivity {
|
||||||
Connectivity::Online => Err(ErrorKind::PackageNotFound {
|
Connectivity::Online => {
|
||||||
package_name: package_name.to_string(),
|
if any_status_code_error.load(Ordering::Relaxed) {
|
||||||
status_code_error: 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()),
|
Connectivity::Offline => Err(ErrorKind::Offline(package_name.to_string()).into()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -556,20 +556,14 @@ pub async fn check_url(
|
||||||
Ok(response) => response,
|
Ok(response) => response,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
return match err.kind() {
|
return match err.kind() {
|
||||||
uv_client::ErrorKind::PackageNotFound {
|
uv_client::ErrorKind::PackageNotFound(_) => {
|
||||||
status_code_error: false,
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
// The package doesn't exist, it's the first upload of the package.
|
// The package doesn't exist, it's the first upload of the package.
|
||||||
warn!(
|
warn!(
|
||||||
"Package not found in the registry; skipping upload check for {filename}"
|
"Package not found in the registry; skipping upload check for {filename}"
|
||||||
);
|
);
|
||||||
Ok(false)
|
Ok(false)
|
||||||
}
|
}
|
||||||
uv_client::ErrorKind::PackageNotFound {
|
uv_client::ErrorKind::StatusCodeError(_) => {
|
||||||
status_code_error: true,
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
// The package may or may not exist, there was an authentication failure.
|
// The package may or may not exist, there was an authentication failure.
|
||||||
// TODO(konsti): We should show the real index error instead.
|
// TODO(konsti): We should show the real index error instead.
|
||||||
let status_code_detail = if index_capabilities.unauthorized(index_url) {
|
let status_code_detail = if index_capabilities.unauthorized(index_url) {
|
||||||
|
|
|
||||||
|
|
@ -200,7 +200,8 @@ impl<Context: BuildContext> ResolverProvider for DefaultResolverProvider<'_, Con
|
||||||
.collect(),
|
.collect(),
|
||||||
)),
|
)),
|
||||||
Err(err) => match err.kind() {
|
Err(err) => match err.kind() {
|
||||||
uv_client::ErrorKind::PackageNotFound { .. } => {
|
uv_client::ErrorKind::PackageNotFound(_)
|
||||||
|
| uv_client::ErrorKind::StatusCodeError(_) => {
|
||||||
if let Some(flat_index) = flat_index
|
if let Some(flat_index) = flat_index
|
||||||
.and_then(|flat_index| flat_index.get(package_name))
|
.and_then(|flat_index| flat_index.get(package_name))
|
||||||
.cloned()
|
.cloned()
|
||||||
|
|
|
||||||
|
|
@ -46,9 +46,10 @@ impl LatestClient<'_> {
|
||||||
Ok(archives) => archives,
|
Ok(archives) => archives,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
return match err.kind() {
|
return match err.kind() {
|
||||||
uv_client::ErrorKind::PackageNotFound { .. } => Ok(None),
|
uv_client::ErrorKind::PackageNotFound(_)
|
||||||
uv_client::ErrorKind::NoIndex(_) => Ok(None),
|
| uv_client::ErrorKind::StatusCodeError(_)
|
||||||
uv_client::ErrorKind::Offline(_) => Ok(None),
|
| uv_client::ErrorKind::NoIndex(_)
|
||||||
|
| uv_client::ErrorKind::Offline(_) => Ok(None),
|
||||||
_ => Err(err),
|
_ => Err(err),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue