Skip to main content

oxide_gen/
error.rs

1//! Error types for `oxide-gen`.
2
3use std::path::PathBuf;
4use thiserror::Error;
5
6/// All errors produced by `oxide-gen`.
7#[derive(Debug, Error)]
8pub enum GenError {
9    /// Failed to read the input spec from disk.
10    #[error("failed to read spec {path}: {source}")]
11    ReadSpec {
12        /// Path that failed.
13        path: PathBuf,
14        /// Underlying IO error.
15        #[source]
16        source: std::io::Error,
17    },
18
19    /// Failed to write generated output to disk.
20    #[error("failed to write {path}: {source}")]
21    WriteOutput {
22        /// Path that failed.
23        path: PathBuf,
24        /// Underlying IO error.
25        #[source]
26        source: std::io::Error,
27    },
28
29    /// The spec could not be parsed.
30    #[error("parse error ({kind}): {message}")]
31    Parse {
32        /// Which parser failed.
33        kind: &'static str,
34        /// Human-readable detail.
35        message: String,
36    },
37
38    /// JSON (de)serialization failed.
39    #[error("json error: {0}")]
40    Json(#[from] serde_json::Error),
41
42    /// YAML (de)serialization failed.
43    #[error("yaml error: {0}")]
44    Yaml(#[from] serde_yaml::Error),
45
46    /// A generic catch-all.
47    #[error(transparent)]
48    Other(#[from] anyhow::Error),
49}
50
51/// Convenient result alias.
52pub type Result<T> = std::result::Result<T, GenError>;