Skip to main content

rusty_detox/
error.rs

1//! Public error type for the rusty-detox library API (FR-042).
2
3use std::path::PathBuf;
4
5/// Error type returned by [`Detox`](crate::Detox) operations.
6///
7/// Pattern-matchable; carries structured payload (path + source-error where
8/// applicable). The `#[non_exhaustive]` marker allows additive variants in
9/// SemVer-minor releases.
10#[non_exhaustive]
11#[derive(Debug, thiserror::Error)]
12pub enum DetoxError {
13    /// Filesystem I/O failure for a specific path.
14    #[error("rusty-detox: I/O error on '{path}': {source}")]
15    Io {
16        /// Path being operated on when the error occurred.
17        path: PathBuf,
18        /// Underlying `std::io::Error`.
19        #[source]
20        source: std::io::Error,
21    },
22
23    /// Configuration file (`detoxrc`) could not be opened or was invalid.
24    #[error("rusty-detox: config error at '{path}': {message}")]
25    Config {
26        /// Config file path (resolved or user-supplied).
27        path: PathBuf,
28        /// Human-readable explanation.
29        message: String,
30    },
31
32    /// `detoxrc` parse error with line + column.
33    #[error("rusty-detox: parse error at {path}:{line}:{column}: {message}")]
34    Parse {
35        /// Config file path.
36        path: PathBuf,
37        /// 1-indexed line number.
38        line: usize,
39        /// 1-indexed column number.
40        column: usize,
41        /// Parser diagnostic message.
42        message: String,
43    },
44
45    /// Collision-resolution exhausted (more than `collision_cap` attempts).
46    #[error("rusty-detox: cannot resolve collision for '{path}' ({attempts} attempts)")]
47    Collision {
48        /// Source path being detoxed.
49        path: PathBuf,
50        /// Number of suffix-disambiguation attempts before giving up.
51        attempts: u32,
52    },
53
54    /// Cross-device rename (EXDEV) — the fallback chain also failed.
55    #[error(
56        "rusty-detox: cross-device rename failed from '{source_path}' to '{target}': {source_err}"
57    )]
58    CrossDevice {
59        /// Source path.
60        source_path: PathBuf,
61        /// Intended target path on the other device.
62        target: PathBuf,
63        /// Underlying error from the fallback chain (copy/fsync/rename/unlink).
64        #[source]
65        source_err: std::io::Error,
66    },
67
68    /// Path was invalid for the active platform (e.g., contains characters not
69    /// representable in the target OS filesystem).
70    #[error("rusty-detox: invalid path '{path}': {reason}")]
71    PathInvalid {
72        /// Offending path.
73        path: PathBuf,
74        /// Human-readable explanation.
75        reason: String,
76    },
77}