prax_cli/
error.rs

1//! CLI error types and result alias.
2
3use miette::Diagnostic;
4use thiserror::Error;
5
6/// Result type alias for CLI operations
7pub type CliResult<T> = Result<T, CliError>;
8
9/// CLI error types
10#[derive(Error, Debug, Diagnostic)]
11pub enum CliError {
12    /// IO error
13    #[error("IO error: {0}")]
14    #[diagnostic(code(prax::io))]
15    Io(#[from] std::io::Error),
16
17    /// Configuration error
18    #[error("Configuration error: {0}")]
19    #[diagnostic(code(prax::config))]
20    Config(String),
21
22    /// Schema parsing error
23    #[error("Schema error: {0}")]
24    #[diagnostic(code(prax::schema))]
25    Schema(String),
26
27    /// Validation error
28    #[error("Validation error: {0}")]
29    #[diagnostic(code(prax::validation))]
30    Validation(String),
31
32    /// Migration error
33    #[error("Migration error: {0}")]
34    #[diagnostic(code(prax::migration))]
35    Migration(String),
36
37    /// Database error
38    #[error("Database error: {0}")]
39    #[diagnostic(code(prax::database))]
40    Database(String),
41
42    /// Command error
43    #[error("Command error: {0}")]
44    #[diagnostic(code(prax::command))]
45    Command(String),
46
47    /// Format error
48    #[error("Format error: {0}")]
49    #[diagnostic(code(prax::format))]
50    Format(String),
51
52    /// Code generation error
53    #[error("Codegen error: {0}")]
54    #[diagnostic(code(prax::codegen))]
55    Codegen(String),
56}
57
58impl From<toml::de::Error> for CliError {
59    fn from(err: toml::de::Error) -> Self {
60        CliError::Config(format!("Failed to parse TOML: {}", err))
61    }
62}
63
64impl From<toml::ser::Error> for CliError {
65    fn from(err: toml::ser::Error) -> Self {
66        CliError::Config(format!("Failed to serialize TOML: {}", err))
67    }
68}