Skip to main content

dodot_lib/
error.rs

1use std::path::PathBuf;
2use thiserror::Error;
3
4/// The single error type for all dodot operations.
5///
6/// Each variant carries enough context to produce a useful error message
7/// without needing to inspect the source chain.
8#[derive(Error, Debug)]
9#[non_exhaustive]
10pub enum DodotError {
11    #[error("filesystem error at {path}: {source}")]
12    Fs {
13        path: PathBuf,
14        source: std::io::Error,
15    },
16
17    #[error("symlink conflict: {path} already exists and is not managed by dodot")]
18    SymlinkConflict { path: PathBuf },
19
20    #[error("protected path: {path} cannot be symlinked")]
21    ProtectedPath { path: PathBuf },
22
23    #[error("pack not found: {name}")]
24    PackNotFound { name: String },
25
26    #[error("pack is invalid: {name}: {reason}")]
27    PackInvalid { name: String, reason: String },
28
29    #[error("handler not found: {name}")]
30    HandlerNotFound { name: String },
31
32    #[error("config error: {0}")]
33    Config(String),
34
35    #[error("command failed: {command} (exit code {exit_code})\n{stderr}")]
36    CommandFailed {
37        command: String,
38        exit_code: i32,
39        stderr: String,
40    },
41
42    #[error("invalid pattern {pattern}: {reason}")]
43    InvalidPattern { pattern: String, reason: String },
44
45    #[error("cross-pack deployment conflict detected (--force does not override this):\n{}", crate::conflicts::format_conflicts(.conflicts))]
46    CrossPackConflict {
47        conflicts: Vec<crate::conflicts::Conflict>,
48    },
49
50    #[error("{0}")]
51    Other(String),
52}
53
54/// Convenience alias used throughout the crate.
55pub type Result<T> = std::result::Result<T, DodotError>;
56
57/// Helper to wrap an `io::Error` with the path that caused it.
58pub(crate) fn fs_err(path: impl Into<PathBuf>, source: std::io::Error) -> DodotError {
59    DodotError::Fs {
60        path: path.into(),
61        source,
62    }
63}