zlayer_toolchain/error.rs
1//! Error types for the toolchain provisioning subsystem.
2//!
3//! The variant names (`RegistryError`, `CacheError`, `IoError`) mirror the
4//! subset of `zlayer_builder::error::BuildError` this crate bridges to via a
5//! `From` impl in the builder, so keg-provisioning errors (source build +
6//! prebuilt fetch) flow back through `?` at the builder call sites unchanged.
7
8use thiserror::Error;
9
10/// Errors raised while resolving or installing a runtime toolchain.
11#[derive(Debug, Error)]
12pub enum ToolchainError {
13 /// Registry / download / resolution failure (Homebrew API, GHCR blob pull,
14 /// `RepoSources` discovery, archive extraction, …).
15 #[error("Registry error: {message}")]
16 RegistryError {
17 /// Underlying registry error description.
18 message: String,
19 },
20
21 /// Cache or config-serialisation failure.
22 #[error("Cache error: {message}")]
23 CacheError {
24 /// Underlying cache error description.
25 message: String,
26 },
27
28 /// A requested capability is not implemented in this wave (e.g. the
29 /// Windows toolchain path). Distinct from a panic / `todo!()` so callers
30 /// get a clean, matchable error instead of an abort.
31 #[error("not implemented: {0}")]
32 NotImplemented(String),
33
34 /// A downloaded artifact's sha256 did not match the expected digest (either
35 /// a formula `urls.stable.checksum`, an upstream-published digest, or a
36 /// lockfile pin). The partial download is deleted before this is returned.
37 #[error("digest mismatch for {tool}: expected {expected}, got {actual}")]
38 DigestMismatch {
39 /// The tool / artifact whose digest failed to verify.
40 tool: String,
41 /// The expected sha256 (bare lowercase hex).
42 expected: String,
43 /// The sha256 actually computed over the downloaded bytes.
44 actual: String,
45 },
46
47 /// Underlying I/O error.
48 #[error("IO error: {0}")]
49 IoError(#[from] std::io::Error),
50}
51
52/// Result alias for toolchain operations.
53pub type Result<T, E = ToolchainError> = std::result::Result<T, E>;