Skip to main content

drizzle_cli/
error.rs

1//! Error types for the CLI
2
3use thiserror::Error;
4
5use crate::config::Error;
6
7/// CLI errors
8#[derive(Debug, Error)]
9pub enum CliError {
10    /// Configuration error
11    #[error("Configuration error: {0}")]
12    Config(#[from] Error),
13
14    /// I/O error
15    #[error("I/O error: {0}")]
16    IoError(String),
17
18    /// No schema files found
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    /// Dialect mismatch between snapshots
27    #[error("Dialect mismatch between previous and current snapshots")]
28    DialectMismatch,
29
30    /// Database connection error
31    #[error("Database connection failed: {0}")]
32    ConnectionError(String),
33
34    /// Migration execution error
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    /// Missing database driver
50    #[error("No driver available for {dialect}. Build with '{feature}' feature enabled.")]
51    MissingDriver {
52        dialect: &'static str,
53        feature: &'static str,
54    },
55
56    /// Operation not supported for this driver.
57    ///
58    /// Used for codegen-only drivers (e.g. `durable-sqlite` — no way to reach
59    /// a running DO from the CLI) and for remote drivers the CLI hasn't been
60    /// wired to yet (e.g. `d1-http`).
61    #[error("{operation} is not supported for driver '{driver}'. {hint}")]
62    UnsupportedForDriver {
63        operation: &'static str,
64        driver: &'static str,
65        hint: &'static str,
66    },
67
68    /// Other errors
69    #[error("{0}")]
70    Other(String),
71}