1use miette::Diagnostic;
4use thiserror::Error;
5
6pub type CliResult<T> = Result<T, CliError>;
8
9#[derive(Error, Debug, Diagnostic)]
11pub enum CliError {
12 #[error("IO error: {0}")]
14 #[diagnostic(code(prax::io))]
15 Io(#[from] std::io::Error),
16
17 #[error("Configuration error: {0}")]
19 #[diagnostic(code(prax::config))]
20 Config(String),
21
22 #[error("Schema error: {0}")]
24 #[diagnostic(code(prax::schema))]
25 Schema(String),
26
27 #[error("Validation error: {0}")]
29 #[diagnostic(code(prax::validation))]
30 Validation(String),
31
32 #[error("Migration error: {0}")]
34 #[diagnostic(code(prax::migration))]
35 Migration(String),
36
37 #[error("Database error: {0}")]
39 #[diagnostic(code(prax::database))]
40 Database(String),
41
42 #[error("Command error: {0}")]
44 #[diagnostic(code(prax::command))]
45 Command(String),
46
47 #[error("Format error: {0}")]
49 #[diagnostic(code(prax::format))]
50 Format(String),
51
52 #[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}