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("The default mount path (/mnt/sshfs) could not be prepared. Mounting there will fail until this is fixed")]
22    DefaultBasePathIO(std::path::PathBuf, std::io::Error),
23
24    /// Happens when a test directory (e.g. `/mnt/sshfs/_sftpman_test_1234567890`) under the default mount path could not be prepared.
25    #[error("A test directory under the default mount path (/mnt/sshfs) could not be prepared. Mounting there will fail until this is fixed")]
26    TestUnderBasePathIO(std::path::PathBuf, std::io::Error),
27}
28
29#[derive(Error, Debug)]
30pub enum SftpManError {
31    /// Happens when any other generic error occurs.
32    #[error("Generic error")]
33    Generic(String),
34
35    /// Happens when the mounts configuration directory does not exist.
36    #[error("The mounts configuration directory does not exist")]
37    NoMountsConfigDirectory,
38
39    /// Happens when `mnt::get_submounts` fails to parse the mount list.
40    #[error("The current mounts could not be parsed")]
41    MountListParse(#[from] mnt::ParseError),
42
43    /// Happens when the mount config definition cannot be read.
44    #[error("The mount config definition could not be read")]
45    FilesystemMountDefinitionRead(std::path::PathBuf, std::io::Error),
46
47    /// Happens when the mount config definition file cannot be removed.
48    #[error("The mount config definition could not be removed")]
49    FilesystemMountDefinitionRemove(std::path::PathBuf, std::io::Error),
50
51    /// Happens when the mount config definition cannot be parsed as JSON.
52    #[error("The mount config definition could not be parsed")]
53    JSON(std::path::PathBuf, serde_json::Error),
54
55    /// Happens when a given mount path was found, but it was not of the expected type (e.g. `fuse.sshfs`).
56    #[error("The mount path  was found, but it was not of the expected type")]
57    MountVfsTypeMismatch {
58        path: std::path::PathBuf,
59        found_vfs_type: String,
60        expected_vfs_type: String,
61    },
62
63    /// Happens when the mount command cannot be constructed.
64    #[error("The mount command could not be constructed")]
65    MountCommandBuilding(String),
66
67    /// Happens when the mount command cannot be executed.
68    #[error("The mount command could not be executed")]
69    CommandExecution(std::process::Command, std::io::Error),
70
71    /// Happens when the mount command was executed, but was unsuccessful.
72    #[error("The command was executed, but was unsuccessful")]
73    CommandUnsuccessful(std::process::Command, std::process::Output),
74
75    /// Happens when the mount directory could not be prepared.
76    #[error("The mount directory could not be prepared")]
77    IO(std::path::PathBuf, std::io::Error),
78}