char/avril

(wip) why'd you have to go and make things so complicaaaaated?

git clone https://git.t4t.associates/char/avril

Charlotte Somdeslop: remove temporary string shims5e9a653

main
6.1 KiB153 linesraw
1use std::sync::Arc;
2
3/// Failures acquiring, verifying, and resolving registry packages.
4///
5/// Every variant preserves the historical message so lockfile, cache, and
6/// authority diagnostics stay stable; the structure lets callers match on
7/// failure kinds instead of substrings.
8#[derive(Clone, Debug, thiserror::Error)]
9pub enum RegistryError {
10    #[error(transparent)]
11    Url(#[from] url::ParseError),
12    #[error(transparent)]
13    Caps(#[from] crate::caps::CapabilitiesError),
14    #[error(transparent)]
15    Io(Arc<std::io::Error>),
16    #[error(transparent)]
17    Json(Arc<serde_json::Error>),
18    #[error(transparent)]
19    Fjson(#[from] serde_fjson::Error),
20    #[error(transparent)]
21    Hyper(Arc<hyper::Error>),
22    // -- mod.rs: options and lockfile -------------------------------------
23    #[error("Update and frozen-lock modes cannot be combined")]
24    UpdateAndFrozen,
25    #[error("npm project root must be an absolute path")]
26    NpmProjectRootNotAbsolute,
27    #[error("Frozen lockfile does not exist: {}", path.display())]
28    FrozenLockfileDoesNotExist { path: std::path::PathBuf },
29    #[error("HTTP package configs cannot use the configured JSR registry: {name}")]
30    HttpConfigUsesJsrRegistry { name: String },
31    #[error("HTTP package configs cannot redirect into the configured JSR registry: {url}")]
32    HttpConfigRedirectsIntoJsr { url: String },
33    #[error("Frozen lockfile is missing remote source: {name}")]
34    FrozenLockfileMissingRemote { name: String },
35    #[error("Remote integrity or final URL mismatch: {name}")]
36    RemoteIntegrityMismatch { name: String },
37    #[error("HTTP module was not acquired: {name}")]
38    HttpModuleNotAcquired { name: String },
39    #[error("Cannot prune a frozen lockfile")]
40    PruneFrozen,
41    #[error("Lockfile changed concurrently for {key}")]
42    LockfileChanged { key: String },
43    #[error("Locked metadata changed for {url}")]
44    LockedMetadataChanged { url: String },
45    #[error("Locked npm package changed for {key}")]
46    LockedNpmPackageChanged { key: String },
47    #[error("Locked npm instance changed for {id}")]
48    LockedNpmInstanceChanged { id: String },
49    #[error("Missing acquired artifact while vendoring: {name}")]
50    MissingVendoredArtifact { name: String },
51    #[error("npm instance registry mismatch: {package}")]
52    NpmInstanceRegistryMismatch { package: String },
53    #[error("npm file integrity mismatch: {rel}")]
54    NpmFileIntegrityMismatch { rel: String },
55    #[error("Offline package cache miss: {url}")]
56    OfflineCacheMiss { url: String },
57    #[error("Registry returned {status} for {url}")]
58    RegistryStatus { status: String, url: String },
59    #[error("Registry returned HTML instead of an artifact: {url}")]
60    RegistryHtmlArtifact { url: String },
61    #[error("Registry artifact is too large: {url}")]
62    RegistryArtifactTooLarge { url: String },
63    #[error("Registry request timed out: {url}")]
64    RegistryTimeout { url: String },
65    #[error("Package integrity mismatch")]
66    IntegrityMismatch,
67    #[error("{name}: Package integrity mismatch")]
68    VerifyMismatch { name: String },
69    #[error("Package artifacts must be regular files")]
70    ArtifactNotRegularFile,
71    #[error("Cached package artifact is too large")]
72    CachedArtifactTooLarge,
73    #[error("Lockfile must be a regular file")]
74    LockfileNotRegularFile,
75    #[error("{name}: not UTF-8")]
76    LockfileNotUtf8 { name: String },
77    #[error("{detail}")]
78    LockfileParse { detail: String },
79    #[error("{name}: {source}")]
80    LockfileJson {
81        name: String,
82        source: std::sync::Arc<serde_json::Error>,
83    },
84    #[error("Registry must be an absolute base URL without credentials, query, or fragment")]
85    InvalidRegistryBaseUrl,
86    #[error("Lockfile is too large")]
87    LockfileTooLarge,
88    #[error("Lockfile needs a parent directory")]
89    LockfileNeedsParent,
90    #[error("Output needs a parent directory")]
91    OutputNeedsParent,
92    #[error("Registries require HTTPS (HTTP is allowed only for loopback testing)")]
93    RegistryRequiresHttps,
94    #[error("Unsupported lockfile version: {version}")]
95    UnsupportedLockfileVersion { version: u32 },
96    #[error("Lockfile JSR registry does not match the configured JSR registry")]
97    LockfileJsrRegistryMismatch,
98    #[error("Lockfile version 1 cannot carry npm pins")]
99    LockfileV1NpmPins,
100    #[error("Lockfile npm registry does not match the configured npm registry")]
101    LockfileNpmRegistryMismatch,
102    #[error("Lockfile npm packages require an npm registry")]
103    LockfileNpmPackagesWithoutRegistry,
104    #[error("Registry module cannot use a remote lock entry: {name}")]
105    RegistryModuleRemoteLockEntry { name: String },
106    #[error("{0} kept changing while it was being updated")]
107    FileKeptChanging(String),
108    #[error("Output must be a regular non-symlink file")]
109    OutputNotRegularFile,
110
111    #[error("Module is not UTF-8: {name}")]
112    ModuleNotUtf8 { name: String },
113    #[error("HTTP acquisition worker stopped")]
114    HttpAcquisitionWorkerStopped,
115    #[error("Package acquisition worker stopped")]
116    PackageAcquisitionWorkerStopped,
117    #[error("{detail}")]
118    WorkerJoin { detail: String },
119    #[error("{detail}")]
120    Persist { detail: String },
121
122    // -- sub-registry errors (each module's own type; transparent here) ---
123    #[error("{detail}")]
124    HttpRequest { detail: String },
125    #[error(transparent)]
126    Http(#[from] super::http::HttpError),
127    #[error(transparent)]
128    Jsr(#[from] super::jsr::JsrError),
129    #[error(transparent)]
130    Npm(#[from] super::npm::NpmError),
131    #[error(transparent)]
132    NpmStorage(#[from] super::npm::storage::StorageError),
133}
134// Explicit textual rendering for generic plumbing (such as update_file)
135// shared with callers that carry their own error types. Prefer carrying
136// RegistryError itself wherever possible.
137impl From<RegistryError> for String {
138    fn from(error: RegistryError) -> Self {
139        error.to_string()
140    }
141}
142
143impl From<std::io::Error> for RegistryError {
144    fn from(error: std::io::Error) -> Self {
145        Self::Io(Arc::new(error))
146    }
147}
148
149impl From<serde_json::Error> for RegistryError {
150    fn from(error: serde_json::Error) -> Self {
151        Self::Json(Arc::new(error))
152    }
153}