Skip to main content

fren_date/
error.rs

1//! Error type for the `fren` library.
2//!
3//! All fallible public functions return `Result<T, FrenError>`. The library
4//! never panics on user input.
5
6use std::path::PathBuf;
7use thiserror::Error;
8
9/// Top-level error for the `fren` library.
10#[derive(Debug, Error)]
11#[non_exhaustive]
12pub enum FrenError {
13    /// I/O error from the filesystem layer.
14    #[error("I/O error at {path}: {source}")]
15    Io {
16        /// Path the error relates to (when known).
17        path: PathBuf,
18        /// Underlying I/O error.
19        #[source]
20        source: std::io::Error,
21    },
22
23    /// A rename target already exists (conflict policy = abort).
24    #[error("target already exists: {0}")]
25    TargetExists(PathBuf),
26
27    /// Two plans within the same batch want to rename to the same target.
28    #[error("within-batch collision: {a} and {b} both want to rename to {target}")]
29    WithinBatchCollision {
30        /// First plan's source path.
31        a: PathBuf,
32        /// Second plan's source path.
33        b: PathBuf,
34        /// The target both plans contend for.
35        target: PathBuf,
36    },
37
38    /// A user-facing input was invalid (bad path, bad option value).
39    #[error("invalid input: {0}")]
40    InvalidInput(String),
41
42    /// A feature is reserved for a future release.
43    #[error("not yet implemented: {0}")]
44    NotYetImplemented(String),
45}