Skip to main content

airbender_build/
errors.rs

1//! Error types surfaced by guest artifact building.
2
3use airbender_core::host::manifest::ManifestError;
4use std::process::ExitStatus;
5
6/// Unified error type for build and packaging operations.
7#[derive(Debug, thiserror::Error)]
8pub enum BuildError {
9    /// Wraps filesystem and process-spawn I/O errors.
10    #[error("io error: {0}")]
11    Io(#[from] std::io::Error),
12
13    /// Reports external command failures with their final exit status.
14    #[error("command `{cmd}` failed with status {status}")]
15    ProcessFailed { cmd: String, status: ExitStatus },
16
17    /// Signals that required metadata was not available.
18    #[error("missing field: {0}")]
19    MissingField(&'static str),
20
21    /// Signals invalid user inputs or metadata content.
22    #[error("invalid config: {0}")]
23    InvalidConfig(String),
24
25    /// Docker CLI was not found on PATH.
26    #[error("docker not found: install Docker and ensure it is on PATH")]
27    DockerNotFound,
28
29    /// Docker daemon is not running or not reachable.
30    #[error("docker daemon is not running: start Docker Desktop or the docker service")]
31    DockerNotRunning,
32
33    /// `docker build` failed while building the reproducible build image.
34    #[error("failed to build Docker image for reproducible build")]
35    DockerBuildFailed,
36
37    /// Guest project is missing a Cargo.lock or it was not generated with the container toolchain.
38    #[error(
39        "Cargo.lock not found in `{project}` or not generated with the container toolchain ({toolchain})\n\
40         fix: cargo +{toolchain} generate-lockfile --manifest-path {project}/Cargo.toml"
41    )]
42    LockfileNotReady {
43        project: String,
44        toolchain: &'static str,
45    },
46}
47
48impl From<ManifestError> for BuildError {
49    fn from(err: ManifestError) -> Self {
50        match err {
51            ManifestError::Io(err) => Self::Io(err),
52            _ => Self::InvalidConfig(err.to_string()),
53        }
54    }
55}
56
57/// Convenience result alias for crate APIs.
58pub type Result<T> = std::result::Result<T, BuildError>;