1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use crate::console;

use std::path::PathBuf;
use thiserror::Error;

/// Errors that occur while building or loading config.
#[derive(Error, Debug)]
pub enum ConfigError {
    /// Errors that occur while loading user-level config from `{cs_config_path}/config.json`.
    #[error("{0}")]
    UserConfigError(#[from] UserConfigError),
    /// Errors that occur while loading a profile from `profile-config.json`.
    #[error("{0}")]
    ProfileLoadError(#[from] ProfileLoadError),
    /// Errors that occur while writing a profile to `profile-config.json`.
    #[error("{0}")]
    ProfileWriteError(#[from] ProfileWriteError),
    /// Errors caused by invalid configuration provided by the user.
    #[error("Invalid config error: {0}")]
    InvalidConfigError(String),
    /// Errors caused by a bug in internal library code. These should be fixed/reported if they occur.
    #[error("Internal error: {0}")]
    InternalError(String),
    /// Errors caused when a CS config directory is expected, but can't be found.
    #[error("CS config dir was set to {0}, but the directory does not exist")]
    MissingConfigDirError(PathBuf),
    /// Error caused when the home directory can't be resolved
    #[error("{0}")]
    HomeDirError(String),
    /// Error caused when fetching credentials fails
    #[error("{0}")]
    CredentialsError(String),
    /// Error caused when a request to Console fails
    #[error("{0}")]
    ConsoleError(#[from] console::WorkSpaceInfoError),
    #[error("{0}")]
    OtherError(String),
}

#[derive(Error, Debug)]
pub enum UserConfigError {
    #[error("Invalid config.json: {0}")]
    JSONError(#[from] serde_json::Error),
    #[error("Error reading config.json: {0}")]
    FSError(#[from] std::io::Error),
}

#[derive(Error, Debug)]
pub enum ProfileLoadError {
    #[error("Invalid profile-config.json: {0}")]
    JSONError(#[from] serde_json::Error),
    #[error("Error reading profile-config.json: {0}")]
    FSError(#[from] std::io::Error),
    #[error("Profile not found: {0}")]
    ProfileNotFoundError(String),
}

#[derive(Error, Debug)]
pub enum ProfileWriteError {
    #[error("Failed to serialize profile as JSON: {0}")]
    JSONError(#[from] serde_json::Error),
    #[error("Error writing profile-config.json: {0}")]
    FSError(#[from] std::io::Error),
    #[error("Profile {0} already exists")]
    AlreadyExists(String),
}