Skip to main content

drizzle_cli/
error.rs

1//! [`CliError`], the error type every command returns.
2
3use thiserror::Error;
4
5use crate::config::Error;
6
7/// An error from a CLI command. Its `Display` text is what the user sees.
8#[derive(Debug, Error)]
9pub enum CliError {
10    /// Loading or reading the config failed.
11    #[error("Configuration error: {0}")]
12    Config(#[from] Error),
13
14    /// A file or folder operation failed.
15    #[error("I/O error: {0}")]
16    IoError(String),
17
18    /// No schema files matched the configured paths.
19    #[error("No schema files found matching: {0}")]
20    NoSchemaFiles(String),
21
22    /// Schema source failed to parse or used attributes the macros reject.
23    #[error("Schema parse failed:\n  {0}")]
24    SchemaParse(String),
25
26    /// The previous and current snapshots use different dialects.
27    #[error("Dialect mismatch between previous and current snapshots")]
28    DialectMismatch,
29
30    /// Connecting to the database failed.
31    #[error("Database connection failed: {0}")]
32    ConnectionError(String),
33
34    /// Planning, verifying, or applying migrations failed.
35    #[error("Migration failed: {0}")]
36    MigrationError(String),
37
38    /// A command that needs a live database found no credentials.
39    #[error(
40        "No database credentials configured: `{0}` needs a database connection \
41         (add a [dbCredentials] section to drizzle.config.toml)"
42    )]
43    MissingCredentials(&'static str),
44
45    /// The user declined to continue, so nothing was applied.
46    #[error("{0}")]
47    Aborted(String),
48
49    /// The CLI was built without the driver feature this database needs.
50    #[error("No driver available for {dialect}. Build with '{feature}' feature enabled.")]
51    MissingDriver {
52        /// Database kind, for the message.
53        dialect: &'static str,
54        /// Cargo feature to enable.
55        feature: &'static str,
56    },
57
58    /// Operation not supported for this driver.
59    ///
60    /// Used for drivers the CLI cannot drive for this operation, such as
61    /// `aws-data-api` (not wired up yet) and MySQL migration repair.
62    #[error("{operation} is not supported for driver '{driver}'. {hint}")]
63    UnsupportedForDriver {
64        /// What was attempted.
65        operation: &'static str,
66        /// The driver in use.
67        driver: &'static str,
68        /// What to do instead.
69        hint: &'static str,
70    },
71
72    /// A run without a terminal met rename-or-create decisions that no hint
73    /// answers. Holds the report listing them (as drizzle-kit prints it);
74    /// the binary prints it to stdout and exits with code 2.
75    #[error("{0}")]
76    MissingHints(String),
77
78    /// `--hints` / `--hints-file` could not be read or does not fit the
79    /// diff (for example a rename whose `from` is not a deleted entity).
80    #[error("Invalid hints: {0}")]
81    InvalidHints(String),
82
83    /// Any other failure, with its message.
84    #[error("{0}")]
85    Other(String),
86}