1use aube_codes::errors;
7
8#[derive(Debug, thiserror::Error)]
9pub enum Error {
10 #[error(
11 "the project requires Node.js {requested} but no satisfying version is available{hint}"
12 )]
13 VersionUnsatisfied { requested: String, hint: String },
14
15 #[error("no Node.js release satisfies {requested}{platform_note}")]
16 NoMatchingVersion {
17 requested: String,
18 platform_note: String,
19 },
20
21 #[error("failed to download {url}: {reason}")]
22 DownloadFailed { url: String, reason: String },
23
24 #[error(
25 "checksum mismatch for {url}: expected sha256 {expected}, got {actual} — the archive was discarded"
26 )]
27 ChecksumMismatch {
28 url: String,
29 expected: String,
30 actual: String,
31 },
32
33 #[error("failed to extract Node.js archive: {reason}")]
34 ExtractFailed { reason: String },
35
36 #[error("mise failed to install {version}: {reason}")]
39 MiseInstallFailed { version: String, reason: String },
40
41 #[error(
42 "no Node.js build is published for {platform}; set nodeDownloadMirrors to a mirror that carries one, or install Node via mise or your system package manager"
43 )]
44 UnsupportedPlatform { platform: String },
45
46 #[error(
51 "no aube release build is published for {platform}; install aube via mise or your system package manager"
52 )]
53 NoReleaseBuild { platform: String },
54
55 #[error("offline mode is active and {what} is not cached")]
56 Offline { what: String },
57
58 #[error("{context}: {source}")]
59 Io {
60 context: String,
61 #[source]
62 source: std::io::Error,
63 },
64}
65
66impl Error {
67 pub fn code(&self) -> &'static str {
69 match self {
70 Error::VersionUnsatisfied { .. } => errors::ERR_AUBE_RUNTIME_VERSION_UNSATISFIED,
71 Error::NoMatchingVersion { .. } => errors::ERR_AUBE_RUNTIME_NO_MATCHING_VERSION,
72 Error::DownloadFailed { .. } => errors::ERR_AUBE_RUNTIME_DOWNLOAD_FAILED,
73 Error::ChecksumMismatch { .. } => errors::ERR_AUBE_RUNTIME_CHECKSUM_MISMATCH,
74 Error::ExtractFailed { .. } => errors::ERR_AUBE_RUNTIME_EXTRACT_FAILED,
75 Error::MiseInstallFailed { .. } => errors::ERR_AUBE_RUNTIME_MISE_INSTALL_FAILED,
76 Error::UnsupportedPlatform { .. } => errors::ERR_AUBE_RUNTIME_UNSUPPORTED_PLATFORM,
77 Error::NoReleaseBuild { .. } => errors::ERR_AUBE_SELF_UPDATE_UNSUPPORTED_PLATFORM,
78 Error::Offline { .. } => errors::ERR_AUBE_OFFLINE,
79 Error::Io { .. } => errors::ERR_AUBE_RUNTIME_IO,
83 }
84 }
85
86 pub(crate) fn io(context: impl Into<String>, source: std::io::Error) -> Self {
87 Error::Io {
88 context: context.into(),
89 source,
90 }
91 }
92}