1#[cfg(feature = "__git")]
4pub use crate::index::git_remote::GitError;
5#[cfg(feature = "local")]
6pub use crate::index::local::LocalRegistryError;
7
8#[derive(Debug, thiserror::Error)]
10pub enum Error {
11 #[error(transparent)]
13 Cache(#[from] CacheError),
14 #[error("unable to use non-utf8 path {:?}", .0)]
17 NonUtf8Path(std::path::PathBuf),
18 #[error("environment variable {} has a non-utf8 value", .0)]
20 NonUtf8EnvVar(std::borrow::Cow<'static, str>),
21 #[error(transparent)]
23 InvalidKrateName(#[from] InvalidKrateName),
24 #[error("registry '{}' was not located in any .cargo/config.toml", .0)]
27 UnknownRegistry(String),
28 #[error(transparent)]
30 Io(#[from] std::io::Error),
31 #[error("I/O operation failed for path '{}': {}", .1, .0)]
33 IoPath(#[source] std::io::Error, crate::PathBuf),
34 #[error(transparent)]
36 InvalidUrl(#[from] InvalidUrl),
37 #[error(transparent)]
39 Json(#[from] serde_json::Error),
40 #[error(transparent)]
42 Toml(#[from] Box<toml_span::Error>),
43 #[error("index entry contained no versions for the crate")]
45 NoCrateVersions,
46 #[error(transparent)]
48 Http(#[from] HttpError),
49 #[cfg(feature = "__git")]
51 #[error(transparent)]
52 Git(#[from] GitError),
53 #[error(transparent)]
55 Semver(#[from] semver::Error),
56 #[cfg(feature = "local")]
58 #[error(transparent)]
59 Local(#[from] LocalRegistryError),
60 #[error(transparent)]
62 Lock(#[from] crate::utils::flock::FileLockError),
63}
64
65impl From<std::path::PathBuf> for Error {
66 fn from(p: std::path::PathBuf) -> Self {
67 Self::NonUtf8Path(p)
68 }
69}
70
71#[derive(Debug, Copy, Clone)]
73pub enum ReservedNameKind {
74 Keyword,
76 Artifact,
78 Windows,
80 Standard,
82}
83
84impl std::fmt::Display for ReservedNameKind {
85 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
86 match self {
87 Self::Keyword => f.write_str("rustlang keyword"),
88 Self::Artifact => f.write_str("cargo artifact"),
89 Self::Windows => f.write_str("windows reserved"),
90 Self::Standard => f.write_str("rustlang std library"),
91 }
92 }
93}
94
95#[derive(Debug, thiserror::Error)]
97pub enum InvalidKrateName {
98 #[error("crate name had an invalid length of '{0}'")]
100 InvalidLength(usize),
101 #[error("invalid character '{invalid}` @ {index}")]
103 InvalidCharacter {
104 invalid: char,
106 index: usize,
108 },
109 #[error("the name '{reserved}' is reserved as '{kind}`")]
111 ReservedName {
112 reserved: &'static str,
114 kind: ReservedNameKind,
116 },
117}
118
119#[derive(Debug, thiserror::Error)]
121#[error("the url '{url}' is invalid")]
122pub struct InvalidUrl {
123 pub url: String,
125 pub source: InvalidUrlError,
127}
128
129#[derive(Debug, thiserror::Error)]
131pub enum InvalidUrlError {
132 #[error("sparse indices require the use of a url that starts with `sparse+http`")]
134 MissingSparse,
135 #[error("the scheme modifier is unknown")]
137 UnknownSchemeModifier,
138 #[error("the scheme is missing")]
140 MissingScheme,
141 #[error("attempted to create a git index for a sparse URL")]
143 SparseForGit,
144}
145
146#[derive(Debug, thiserror::Error)]
148pub enum CacheError {
149 #[error("the cache entry is malformed")]
151 InvalidCacheEntry,
152 #[error("the cache entry is an old, unsupported version")]
154 OutdatedCacheVersion,
155 #[error("the cache entry is an unknown version, possibly written by a newer cargo version")]
157 UnknownCacheVersion,
158 #[error(
160 "the cache entry's index version is unknown, possibly written by a newer cargo version"
161 )]
162 UnknownIndexVersion,
163 #[error("the cache entry's revision does not match the current revision")]
168 OutdatedRevision,
169 #[error("a specific version in the cache entry is malformed")]
171 InvalidCrateVersion,
172}
173
174#[derive(Debug, thiserror::Error)]
176pub enum HttpError {
177 #[cfg(any(feature = "sparse", feature = "local-builder"))]
179 #[error(transparent)]
180 Reqwest(#[from] reqwest::Error),
181 #[error("status code '{code}': {msg}")]
184 StatusCode {
185 code: http::StatusCode,
187 msg: &'static str,
189 },
190 #[error(transparent)]
192 Http(#[from] http::Error),
193 #[error(transparent)]
195 InvalidHeaderValue(#[from] http::header::InvalidHeaderValue),
196 #[error("request could not be completed in the allotted timeframe")]
199 Timeout,
200}