Skip to main content

nodex_core/
error.rs

1use std::path::PathBuf;
2
3/// All errors that can occur in nodex-core.
4#[derive(Debug, thiserror::Error)]
5pub enum Error {
6    #[error("IO error at {path}")]
7    Io {
8        path: PathBuf,
9        #[source]
10        source: std::io::Error,
11    },
12
13    #[error("frontmatter parse error at {path}: {message}")]
14    Frontmatter { path: PathBuf, message: String },
15
16    #[error("YAML parse error at {path}")]
17    Yaml {
18        path: PathBuf,
19        #[source]
20        source: yaml_serde::Error,
21    },
22
23    #[error("config error: {0}")]
24    Config(String),
25
26    #[error("duplicate node id {id:?} found at {first} and {second}")]
27    DuplicateId {
28        id: String,
29        first: PathBuf,
30        second: PathBuf,
31    },
32
33    #[error("supersedes cycle detected: {chain:?}")]
34    SupersedesCycle { chain: Vec<String> },
35
36    #[error("invalid lifecycle transition: {from:?} -> {to:?} for node {node_id:?}")]
37    InvalidTransition {
38        node_id: String,
39        from: String,
40        to: String,
41    },
42
43    #[error("node not found: {0}")]
44    NodeNotFound(String),
45
46    #[error("already exists: {path}")]
47    AlreadyExists { path: PathBuf },
48
49    #[error("path escapes project root: {path}")]
50    PathEscapesRoot { path: PathBuf },
51
52    #[error("{0}")]
53    Other(String),
54}
55
56pub type Result<T> = std::result::Result<T, Error>;