Skip to main content

vcs_modify_guard/
error.rs

1use std::{error::Error, io, path::PathBuf};
2
3use snafu::Snafu;
4
5/// Errors returned by `vcs-modify-guard` operations.
6#[derive(Debug, Snafu)]
7#[non_exhaustive]
8#[snafu(visibility(pub(crate)))]
9pub enum ModifyGuardError {
10    /// The specified path does not refer to a repository supported by the
11    /// enabled backends.
12    #[snafu(display("not a VCS repository: {}", path.display()))]
13    NotARepository {
14        /// The path that was rejected.
15        path: PathBuf,
16    },
17    /// The specified path refers to a repository without a worktree, such as a
18    /// Git bare repository.
19    #[snafu(display("repository has no worktree: {}", path.display()))]
20    RepositoryWithoutWorktree {
21        /// The path that was rejected.
22        path: PathBuf,
23    },
24    /// The specified path could not be accessed.
25    #[snafu(display("path is inaccessible: {}", path.display()))]
26    InaccessiblePath {
27        /// The path that was rejected.
28        path: PathBuf,
29        /// The underlying I/O error.
30        source: io::Error,
31    },
32    /// The specified path was not found.
33    #[snafu(display("path not found: {}", path.display()))]
34    PathNotFound {
35        /// The path that was rejected.
36        path: PathBuf,
37    },
38    /// The specified path could not be resolved to a canonical path.
39    #[snafu(display(
40        "path could not be resolved to a canonical path: {}",
41        path.display()
42    ))]
43    CanonicalizePath {
44        /// The path that was rejected.
45        path: PathBuf,
46        /// The underlying I/O error.
47        source: io::Error,
48    },
49    /// The specified path is not a directory.
50    #[snafu(display("path is not a directory: {}", path.display()))]
51    PathNotADirectory {
52        /// The path that was rejected.
53        path: PathBuf,
54    },
55    /// The specified path does not resolve to a file.
56    #[snafu(display("path does not resolve to a file: {}", path.display()))]
57    PathNotAFile {
58        /// The path that was rejected.
59        path: PathBuf,
60    },
61    /// The specified path does not resolve to a valid path within the
62    /// repository worktree.
63    #[snafu(display(
64        "path does not resolve to a valid path within the repository worktree: {}",
65        path.display()
66    ))]
67    ResolveAsWorktreeRelativePath {
68        /// The path that was rejected.
69        path: PathBuf,
70    },
71    /// The specified path does not resolve to a single file within the repository worktree.
72    #[snafu(display(
73        "path does not resolve to a single file within the repository worktree: {}",
74        wt_path.display()
75    ))]
76    AmbiguousFilePath {
77        /// The path that was rejected.
78        wt_path: PathBuf,
79    },
80    /// VCS backend error.
81    #[snafu(transparent)]
82    Backend {
83        /// The underlying error returned by the VCS backend.
84        source: Box<dyn Error + Send + Sync + 'static>,
85    },
86}
87
88// assert that ModifyGuardError is Send + Sync
89const _: () = {
90    const fn assert_send_sync<T: Send + Sync>() {}
91    assert_send_sync::<ModifyGuardError>();
92};