2023-11-06 15:06:49 +01:00
|
|
|
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;
|
2023-11-10 19:33:49 +01:00
|
|
|
use url::Url;
|
2023-10-04 19:43:15 -04:00
|
|
|
|
2023-11-09 18:45:41 -08:00
|
|
|
use distribution_filename::{WheelFilename, WheelFilenameError};
|
2023-11-24 18:47:58 +01:00
|
|
|
use puffin_normalize::PackageName;
|
2023-10-05 21:03:20 -04:00
|
|
|
|
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),
|
|
|
|
|
|
2023-11-28 18:11:14 +01:00
|
|
|
/// Dist-info error
|
2023-11-20 03:38:27 -08:00
|
|
|
#[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}.")]
|
2023-11-10 12:03:40 +01:00
|
|
|
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 },
|
2023-11-06 15:06:49 +01:00
|
|
|
|
|
|
|
|
#[error(transparent)]
|
|
|
|
|
AsyncHttpRangeReader(#[from] AsyncHttpRangeReaderError),
|
|
|
|
|
|
|
|
|
|
#[error("Expected a single .dist-info directory in {0}, found {1}")]
|
|
|
|
|
InvalidDistInfo(WheelFilename, String),
|
|
|
|
|
|
2023-11-09 18:45:41 -08:00
|
|
|
#[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,
|
|
|
|
|
},
|
|
|
|
|
|
2023-11-06 15:06:49 +01:00
|
|
|
#[error("The wheel {0} is not a valid zip file")]
|
|
|
|
|
Zip(WheelFilename, #[source] ZipError),
|
|
|
|
|
|
2023-11-28 18:11:14 +01:00
|
|
|
#[error("Failed to write to the client cache")]
|
2023-11-06 15:06:49 +01:00
|
|
|
IO(#[from] io::Error),
|
2023-11-10 12:03:40 +01:00
|
|
|
|
|
|
|
|
/// 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 {
|
2023-10-04 19:50:17 -04:00
|
|
|
Self::BadJson { source: err, url }
|
2023-10-04 19:43:15 -04:00
|
|
|
}
|
|
|
|
|
}
|