1#[cfg(feature = "local")]
4pub use crate::index::local::LocalRegistryError;
5
6#[derive(Debug, thiserror::Error)]
8pub enum Error {
9 #[error(transparent)]
11 Cache(#[from] CacheError),
12 #[error("unable to use non-utf8 path {:?}", .0)]
15 NonUtf8Path(std::path::PathBuf),
16 #[error("environment variable {} has a non-utf8 value", .0)]
18 NonUtf8EnvVar(std::borrow::Cow<'static, str>),
19 #[error(transparent)]
21 InvalidKrateName(#[from] InvalidKrateName),
22 #[error("registry '{}' was not located in any .cargo/config.toml", .0)]
25 UnknownRegistry(String),
26 #[error(transparent)]
28 Io(#[from] std::io::Error),
29 #[error("I/O operation failed for path '{}': {}", .1, .0)]
31 IoPath(#[source] std::io::Error, crate::PathBuf),
32 #[error(transparent)]
34 InvalidUrl(#[from] InvalidUrl),
35 #[error(transparent)]
37 Json(#[from] serde_json::Error),
38 #[error(transparent)]
40 Toml(#[from] Box<toml_span::Error>),
41 #[error("index entry contained no versions for the crate")]
43 NoCrateVersions,
44 #[error(transparent)]
46 Http(#[from] HttpError),
47 #[error(transparent)]
49 Semver(#[from] semver::Error),
50 #[cfg(feature = "local")]
52 #[error(transparent)]
53 Local(#[from] LocalRegistryError),
54 #[error(transparent)]
56 Lock(#[from] crate::utils::flock::FileLockError),
57}
58
59impl From<std::path::PathBuf> for Error {
60 fn from(p: std::path::PathBuf) -> Self {
61 Self::NonUtf8Path(p)
62 }
63}
64
65#[derive(Debug, Copy, Clone)]
67pub enum ReservedNameKind {
68 Keyword,
70 Artifact,
72 Windows,
74 Standard,
76}
77
78impl std::fmt::Display for ReservedNameKind {
79 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
80 match self {
81 Self::Keyword => f.write_str("rustlang keyword"),
82 Self::Artifact => f.write_str("cargo artifact"),
83 Self::Windows => f.write_str("windows reserved"),
84 Self::Standard => f.write_str("rustlang std library"),
85 }
86 }
87}
88
89#[derive(Debug, thiserror::Error)]
91pub enum InvalidKrateName {
92 #[error("crate name had an invalid length of '{0}'")]
94 InvalidLength(usize),
95 #[error("invalid character '{invalid}` @ {index}")]
97 InvalidCharacter {
98 invalid: char,
100 index: usize,
102 },
103 #[error("the name '{reserved}' is reserved as '{kind}`")]
105 ReservedName {
106 reserved: &'static str,
108 kind: ReservedNameKind,
110 },
111}
112
113#[derive(Debug, thiserror::Error)]
115#[error("the url '{url}' is invalid")]
116pub struct InvalidUrl {
117 pub url: String,
119 pub source: InvalidUrlError,
121}
122
123#[derive(Debug, thiserror::Error)]
125pub enum InvalidUrlError {
126 #[error("sparse indices require the use of a url that starts with `sparse+http`")]
128 MissingSparse,
129 #[error("the scheme modifier is unknown")]
131 UnknownSchemeModifier,
132 #[error("the scheme is missing")]
134 MissingScheme,
135 #[error("attempted to create a git index for a sparse URL")]
137 SparseForGit,
138}
139
140#[derive(Debug, thiserror::Error)]
142pub enum CacheError {
143 #[error("the cache entry is malformed")]
145 InvalidCacheEntry,
146 #[error("the cache entry is an old, unsupported version")]
148 OutdatedCacheVersion,
149 #[error("the cache entry is an unknown version, possibly written by a newer cargo version")]
151 UnknownCacheVersion,
152 #[error(
154 "the cache entry's index version is unknown, possibly written by a newer cargo version"
155 )]
156 UnknownIndexVersion,
157 #[error("the cache entry's revision does not match the current revision")]
162 OutdatedRevision,
163 #[error("a specific version in the cache entry is malformed")]
165 InvalidCrateVersion,
166}
167
168#[derive(Debug, thiserror::Error)]
170pub enum HttpError {
171 #[cfg(any(feature = "sparse", feature = "local-builder"))]
173 #[error(transparent)]
174 Reqwest(#[from] reqwest::Error),
175 #[error("status code '{code}': {msg}")]
178 StatusCode {
179 code: http::StatusCode,
181 msg: &'static str,
183 },
184 #[error(transparent)]
186 Http(#[from] http::Error),
187 #[error(transparent)]
189 InvalidHeaderValue(#[from] http::header::InvalidHeaderValue),
190 #[error("request could not be completed in the allotted timeframe")]
193 Timeout,
194}