Skip to main content

redis_common/
error.rs

1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum RedisCtlError {
5    #[error("Configuration error: {0}")]
6    Config(#[from] ConfigError),
7
8    #[error("Profile error: {0}")]
9    Profile(#[from] ProfileError),
10
11    #[error("Command routing error: {0}")]
12    Routing(#[from] RoutingError),
13}
14
15#[derive(Error, Debug)]
16pub enum ConfigError {
17    #[error("Profile '{name}' not found")]
18    ProfileNotFound { name: String },
19
20    #[error("No default profile set")]
21    NoDefaultProfile,
22
23    #[error("Config file error: {message}")]
24    FileError { message: String },
25}
26
27#[derive(Error, Debug)]
28pub enum ProfileError {
29    #[error("Profile '{name}' is type '{actual_type}' but command requires '{expected_type}'")]
30    TypeMismatch {
31        name: String,
32        actual_type: String,
33        expected_type: String,
34    },
35
36    #[error("Missing credentials for profile '{name}'")]
37    MissingCredentials { name: String },
38}
39
40#[derive(Error, Debug)]
41pub enum RoutingError {
42    #[error(
43        "Command '{command}' exists in both cloud and enterprise. Use 'redisctl cloud {command}' or 'redisctl enterprise {command}'"
44    )]
45    AmbiguousCommand { command: String },
46
47    #[error("Command '{command}' not found in {deployment_type}")]
48    CommandNotFound {
49        command: String,
50        deployment_type: String,
51    },
52
53    #[error(
54        "No profile specified and no default profile set. Use --profile or set REDISCTL_PROFILE"
55    )]
56    NoProfileSpecified,
57}