Skip to main content

laterite_core/
error.rs

1//! The framework-level error taxonomy.
2//!
3//! Application crates layer their own domain errors on top; anything that
4//! crosses a framework boundary (handlers, modules, jobs) converges here so
5//! HTTP mapping and logging stay uniform.
6
7use thiserror::Error;
8
9#[derive(Debug, Error)]
10pub enum CoreError {
11    #[error("configuration error: {0}")]
12    Config(String),
13
14    #[error("database error")]
15    Database(#[from] sqlx::Error),
16
17    #[error("migration '{name}' in module '{module}' changed after being applied")]
18    MigrationDrift { module: String, name: String },
19
20    #[error("migration '{name}' in module '{module}' cannot be reversed")]
21    Irreversible { module: String, name: String },
22
23    #[error("module '{module}' registered more than once")]
24    DuplicateModule { module: String },
25
26    #[error("module '{module}' depends on unregistered module '{dependency}'")]
27    UnknownModuleDependency { module: String, dependency: String },
28
29    #[error("dependency cycle through module '{module}'")]
30    ModuleDependencyCycle { module: String },
31
32    #[error(
33        "module '{module}' requires database capability '{capability}', unavailable on {backend}"
34    )]
35    MissingDbCapability {
36        module: String,
37        capability: String,
38        backend: String,
39    },
40
41    #[error("not found: {0}")]
42    NotFound(String),
43
44    #[error("validation failed: {0}")]
45    Validation(String),
46
47    #[error("unauthorized")]
48    Unauthorized,
49
50    #[error("forbidden: {0}")]
51    Forbidden(String),
52
53    #[error("conflict: {0}")]
54    Conflict(String),
55
56    #[error("internal error: {0}")]
57    Internal(String),
58}
59
60pub type CoreResult<T> = Result<T, CoreError>;