libsftpman/
errors.rs

1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum ManagerInitError {
5    /// Happens when `directories::ProjectDirs` cannot retrieve a valid home directory path from the operating system.
6    #[error("The config directory could not be determined")]
7    NoConfigDirectory,
8}
9
10#[derive(Error, Debug)]
11pub enum PreflightCheckError {
12    /// Happens when a required command (e.g. `sshfs`) cannot be executed.
13    #[error("A required command could not be executed")]
14    CommandExecution(std::process::Command, std::io::Error),
15
16    /// Happens when a required command was executed, but was unsuccessful.
17    #[error("A required command was executed, but was unsuccessful")]
18    CommandUnsuccessful(std::process::Command, std::process::Output),
19
20    /// Happens when the default mount path (e.g. `/mnt/sshfs`) does not exist and cannot be prepared.
21    #[error(
22        "The default mount path (/mnt/sshfs) could not be prepared. Mounting there will fail until this is fixed"
23    )]
24    DefaultBasePathIO(std::path::PathBuf, std::io::Error),
25
26    /// Happens when a test directory (e.g. `/mnt/sshfs/_sftpman_test_1234567890`) under the default mount path could not be prepared.
27    #[error(
28        "A test directory under the default mount path (/mnt/sshfs) could not be prepared. Mounting there will fail until this is fixed"
29    )]
30    TestUnderBasePathIO(std::path::PathBuf, std::io::Error),
31}
32
33#[derive(Error, Debug)]
34pub enum SftpManError {
35    /// Happens when any other generic error occurs.
36    #[error("Generic error")]
37    Generic(String),
38
39    /// Happens when the mounts configuration directory does not exist.
40    #[error("The mounts configuration directory does not exist")]
41    NoMountsConfigDirectory,
42
43    /// Happens when `mnt::get_submounts` fails to parse the mount list.
44    #[error("The current mounts could not be parsed")]
45    MountListParse(#[from] mnt::ParseError),
46
47    /// Happens when the mount config definition cannot be read.
48    #[error("The mount config definition could not be read")]
49    FilesystemMountDefinitionRead(std::path::PathBuf, std::io::Error),
50
51    /// Happens when the mount config definition file cannot be removed.
52    #[error("The mount config definition could not be removed")]
53    FilesystemMountDefinitionRemove(std::path::PathBuf, std::io::Error),
54
55    /// Happens when the mount config definition cannot be parsed as JSON.
56    #[error("The mount config definition could not be parsed")]
57    JSON(std::path::PathBuf, serde_json::Error),
58
59    /// Happens when a given mount path was found, but it was not of the expected type (e.g. `fuse.sshfs`).
60    #[error("The mount path  was found, but it was not of the expected type")]
61    MountVfsTypeMismatch {
62        path: std::path::PathBuf,
63        found_vfs_type: String,
64        expected_vfs_type: String,
65    },
66
67    /// Happens when the mount command cannot be constructed.
68    #[error("The mount command could not be constructed")]
69    MountCommandBuilding(String),
70
71    /// Happens when the mount command cannot be executed.
72    #[error("The mount command could not be executed")]
73    CommandExecution(std::process::Command, std::io::Error),
74
75    /// Happens when the mount command was executed, but was unsuccessful.
76    #[error("The command was executed, but was unsuccessful")]
77    CommandUnsuccessful(std::process::Command, std::process::Output),
78
79    /// Happens when the mount directory could not be prepared.
80    #[error("The mount directory could not be prepared")]
81    IO(std::path::PathBuf, std::io::Error),
82}