Skip to main content

kermit_bench/
error.rs

1//! Error type used across the `kermit-bench` crate.
2
3use std::path::PathBuf;
4
5/// Errors that can occur during benchmark operations.
6#[derive(Debug, thiserror::Error)]
7pub enum BenchError {
8    /// A YAML file failed to parse.
9    #[error("YAML parse error for {path}: {source}")]
10    Yaml {
11        /// The file being parsed.
12        path: PathBuf,
13        /// The underlying serde-yaml error.
14        source: serde_yaml::Error,
15    },
16
17    /// An underlying I/O error (filesystem access, reading cache files, etc.).
18    #[error("I/O error: {0}")]
19    Io(#[from] std::io::Error),
20
21    /// Downloading a relation file failed.
22    #[error("download failed for {url}: {source}")]
23    Download {
24        /// URL that was being fetched.
25        url: String,
26        /// Underlying reqwest error.
27        source: reqwest::Error,
28    },
29
30    /// A benchmark with the requested name does not exist.
31    #[error("benchmark not found: {0}")]
32    NotFound(String),
33
34    /// The benchmark definition is structurally invalid (see
35    /// [`BenchmarkDefinition::validate`](crate::BenchmarkDefinition::validate)).
36    #[error("invalid benchmark definition {name}: {reason}")]
37    Invalid {
38        /// The benchmark name as declared in the YAML.
39        name: String,
40        /// Human-readable description of the invariant that was violated.
41        reason: String,
42    },
43
44    /// The platform cache directory could not be determined.
45    #[error("cache directory not available")]
46    NoCacheDir,
47
48    /// A generator-spec YAML's parameters disagree with the cached
49    /// `meta.json`'s `spec_hash`. Returned by the materialization layer to
50    /// prevent silently re-running an expensive pipeline.
51    #[error(
52        "spec drift for benchmark '{name}': cached spec_hash={actual_hash}, current \
53         spec_hash={expected_hash}; {hint}"
54    )]
55    SpecDrift {
56        /// Benchmark name.
57        name: String,
58        /// Spec hash computed from the workspace YAML at this invocation.
59        expected_hash: String,
60        /// Spec hash recorded in the cached `meta.json`.
61        actual_hash: String,
62        /// Resolution hint shown to the user.
63        hint: String,
64    },
65}