intentional_core/error.rs
1// ---
2// relationships:
3// implements: intent-driven-polyglot-release
4// ---
5
6//! Error types shared by core operations.
7
8use std::path::PathBuf;
9
10/// Core operation result.
11pub type Result<T> = std::result::Result<T, Error>;
12
13/// Errors produced by `intentional-core`.
14#[derive(Debug, thiserror::Error)]
15pub enum Error {
16 /// A configuration or intent is invalid.
17 #[error("validation failed: {0}")]
18 Validation(String),
19
20 /// A required file could not be read or written.
21 #[error("failed to access {path}: {source}")]
22 Io {
23 /// File involved in the operation.
24 path: PathBuf,
25 /// Underlying filesystem error.
26 source: std::io::Error,
27 },
28
29 /// YAML could not be parsed or serialized.
30 #[error("invalid YAML: {0}")]
31 Yaml(#[from] serde_yaml::Error),
32
33 /// Git state could not be discovered or traversed.
34 #[error("git operation failed: {0}")]
35 Git(String),
36
37 /// A semantic version could not be represented.
38 #[error("invalid semantic version: {0}")]
39 Semver(#[from] semver::Error),
40}
41
42impl Error {
43 /// Attach a path to an I/O error.
44 pub(crate) fn io(path: impl Into<PathBuf>, source: std::io::Error) -> Self {
45 Self::Io {
46 path: path.into(),
47 source,
48 }
49 }
50}