Skip to main content

rustinel_core/
errors.rs

1use std::path::PathBuf;
2
3/// All fallible operations in `rustinel-core` return this error.
4///
5/// Messages are written to be human-readable; the CLI surfaces them directly.
6#[derive(Debug, thiserror::Error)]
7pub enum RustinelError {
8    // `#[source]` already exposes the io::Error as the next link in the error
9    // chain; don't also interpolate it into the message (that double-prints it).
10    #[error("I/O error while reading {path}")]
11    Io {
12        path: PathBuf,
13        #[source]
14        source: std::io::Error,
15    },
16
17    #[error("Could not parse Cargo.lock at {path}: {message}")]
18    LockfileParse { path: PathBuf, message: String },
19
20    #[error("Invalid policy: {0}")]
21    InvalidPolicy(String),
22
23    #[error("Could not load advisory database at {path}: {message}")]
24    AdvisoryDb { path: PathBuf, message: String },
25}
26
27impl RustinelError {
28    pub fn io(path: impl Into<PathBuf>, source: std::io::Error) -> Self {
29        Self::Io {
30            path: path.into(),
31            source,
32        }
33    }
34
35    pub fn lockfile_parse(path: impl Into<PathBuf>, message: impl Into<String>) -> Self {
36        Self::LockfileParse {
37            path: path.into(),
38            message: message.into(),
39        }
40    }
41}