Files
uv/crates/puffin-client/src/error.rs
T

86 lines
2.7 KiB
Rust
Raw Normal View History

use std::io;
use async_http_range_reader::AsyncHttpRangeReaderError;
use async_zip::error::ZipError;
2023-10-04 19:43:15 -04:00
use thiserror::Error;
use url::Url;
2023-10-04 19:43:15 -04:00
use distribution_filename::{WheelFilename, WheelFilenameError};
2023-11-24 18:47:58 +01:00
use puffin_normalize::PackageName;
2023-10-04 19:43:15 -04:00
#[derive(Debug, Error)]
2023-10-22 20:18:30 -07:00
pub enum Error {
2023-10-04 19:43:15 -04:00
/// An invalid URL was provided.
#[error(transparent)]
UrlParseError(#[from] url::ParseError),
/// Dist-info error
#[error(transparent)]
InstallWheel(#[from] install_wheel_rs::Error),
2023-11-01 16:52:58 +01:00
#[error("{0} isn't available locally, but making network requests to registries was banned.")]
NoIndex(String),
2023-10-04 19:43:15 -04:00
/// The package was not found in the registry.
///
/// Make sure the package name is spelled correctly and that you've
/// configured the right registry to fetch it from.
2023-10-22 20:18:30 -07:00
#[error("Package `{0}` was not found in the registry.")]
PackageNotFound(String),
2023-10-04 19:43:15 -04:00
2023-10-04 22:21:36 -04:00
/// The metadata file could not be parsed.
2023-11-24 18:47:58 +01:00
#[error("Couldn't parse metadata of {0} from {1}")]
MetadataParseError(WheelFilename, String, #[source] pypi_types::Error),
2023-10-04 22:21:36 -04:00
/// The metadata file was not found in the registry.
2023-11-01 16:52:58 +01:00
#[error("File `{0}` was not found in the registry at {1}.")]
FileNotFound(String, #[source] reqwest::Error),
2023-10-04 22:21:36 -04:00
2023-10-04 19:43:15 -04:00
/// A generic request error happened while making a request. Refer to the
/// error message for more details.
#[error(transparent)]
RequestError(#[from] reqwest::Error),
/// A generic request middleware error happened while making a request.
/// Refer to the error message for more details.
#[error(transparent)]
RequestMiddlewareError(#[from] reqwest_middleware::Error),
2023-11-13 12:41:20 +01:00
#[error("Received some unexpected JSON from {url}")]
BadJson { source: serde_json::Error, url: Url },
#[error(transparent)]
AsyncHttpRangeReader(#[from] AsyncHttpRangeReaderError),
#[error("Expected a single .dist-info directory in {0}, found {1}")]
InvalidDistInfo(WheelFilename, String),
#[error("{0} is not a valid wheel filename")]
WheelFilename(#[from] WheelFilenameError),
2023-11-24 18:47:58 +01:00
#[error("Package metadata name `{metadata}` does not match given name `{given}`")]
NameMismatch {
given: PackageName,
metadata: PackageName,
},
#[error("The wheel {0} is not a valid zip file")]
Zip(WheelFilename, #[source] ZipError),
#[error("Failed to write to the client cache")]
IO(#[from] io::Error),
/// An [`io::Error`] with a filename attached
#[error(transparent)]
Persist(#[from] tempfile::PersistError),
#[error("Failed to serialize response to cache")]
SerdeJson(#[from] serde_json::Error),
2023-10-04 19:43:15 -04:00
}
2023-10-22 20:18:30 -07:00
impl Error {
2023-11-13 12:41:20 +01:00
pub fn from_json_err(err: serde_json::Error, url: Url) -> Self {
Self::BadJson { source: err, url }
2023-10-04 19:43:15 -04:00
}
}