#[cfg(feature = "git")]
pub use crate::index::git_remote::GitError;
#[cfg(feature = "local")]
pub use crate::index::local::LocalRegistryError;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error(transparent)]
Cache(#[from] CacheError),
#[error("unable to use non-utf8 path {:?}", .0)]
NonUtf8Path(std::path::PathBuf),
#[error(transparent)]
InvalidKrateName(#[from] InvalidKrateName),
#[error(transparent)]
Io(#[from] std::io::Error),
#[error("I/O operation failed for path '{}'", .1)]
IoPath(#[source] std::io::Error, crate::PathBuf),
#[error(transparent)]
InvalidUrl(#[from] InvalidUrl),
#[error(transparent)]
Json(#[from] serde_json::Error),
#[error(transparent)]
Toml(#[from] toml::de::Error),
#[error("index entry contained no versions for the crate")]
NoCrateVersions,
#[error(transparent)]
Http(#[from] HttpError),
#[cfg(feature = "git")]
#[error(transparent)]
Git(#[from] GitError),
#[error(transparent)]
Semver(#[from] semver::Error),
#[cfg(feature = "local")]
#[error(transparent)]
Local(#[from] LocalRegistryError),
}
impl From<std::path::PathBuf> for Error {
fn from(p: std::path::PathBuf) -> Self {
Self::NonUtf8Path(p)
}
}
#[derive(Debug, Copy, Clone)]
pub enum ReservedNameKind {
Keyword,
Artifact,
Windows,
Standard,
}
impl std::fmt::Display for ReservedNameKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Keyword => f.write_str("rustlang keyword"),
Self::Artifact => f.write_str("cargo artifact"),
Self::Windows => f.write_str("windows reserved"),
Self::Standard => f.write_str("rustlang std library"),
}
}
}
#[derive(Debug, thiserror::Error)]
pub enum InvalidKrateName {
#[error("crate name had an invalid length of '{0}'")]
InvalidLength(usize),
#[error("invalid character '{invalid}` @ {index}")]
InvalidCharacter {
invalid: char,
index: usize,
},
#[error("the name '{reserved}' is reserved as '{kind}`")]
ReservedName {
reserved: &'static str,
kind: ReservedNameKind,
},
}
#[derive(Debug, thiserror::Error)]
#[error("the url '{url}' is invalid")]
pub struct InvalidUrl {
pub url: String,
pub source: InvalidUrlError,
}
#[derive(Debug, thiserror::Error)]
pub enum InvalidUrlError {
#[error("sparse indices require the use of a url that starts with `sparse+http`")]
MissingSparse,
#[error("the scheme modifier is unknown")]
UnknownSchemeModifier,
#[error("the scheme is missing")]
MissingScheme,
#[error("attempted to create a git index for a sparse URL")]
SparseForGit,
}
#[derive(Debug, thiserror::Error)]
pub enum CacheError {
#[error("the cache entry is malformed")]
InvalidCacheEntry,
#[error("the cache entry is an old, unsupported version")]
OutdatedCacheVersion,
#[error("the cache entry is an unknown version, possibly written by a newer cargo version")]
UnknownCacheVersion,
#[error(
"the cache entry's index version is unknown, possibly written by a newer cargo version"
)]
UnknownIndexVersion,
#[error("the cache entry's revision does not match the current revision")]
OutdatedRevision,
#[error("a specific version in the cache entry is malformed")]
InvalidCrateVersion,
}
#[derive(Debug, thiserror::Error)]
pub enum HttpError {
#[cfg(any(feature = "sparse", feature = "local-builder"))]
#[error(transparent)]
Reqwest(#[from] reqwest::Error),
#[error("status code '{code}': {msg}")]
StatusCode {
code: http::StatusCode,
msg: &'static str,
},
#[error(transparent)]
Http(#[from] http::Error),
}