Skip to main content

dort_core/
error.rs

1use std::path::PathBuf;
2
3pub type Result<T> = std::result::Result<T, Error>;
4
5#[derive(Debug, thiserror::Error)]
6pub enum Error {
7    #[error("{operation}: {path}: {source}")]
8    Io {
9        operation: &'static str,
10        path: PathBuf,
11        #[source]
12        source: std::io::Error,
13    },
14    #[error("invalid TOML: {0}")]
15    Parse(#[from] toml::de::Error),
16    #[error("manifest validation failed:\n{}", .0.join("\n"))]
17    Validation(Vec<String>),
18    #[error("{0}")]
19    Invalid(String),
20    #[error("another Dort writer holds the application lock")]
21    Locked,
22    #[error("no active repository; use --repo or --manifest")]
23    NoRepository,
24}
25
26pub(crate) fn io_error(
27    operation: &'static str,
28    path: impl Into<PathBuf>,
29    source: impl Into<std::io::Error>,
30) -> Error {
31    Error::Io {
32        operation,
33        path: path.into(),
34        source: source.into(),
35    }
36}