Skip to main content

Module macros

Module macros 

Source
Expand description

Declarative domain_error! macro for domain crates.

Eliminates the boilerplate Database, Io, Json, Validation, NotFound, etc. variants that every crate hand-rolls. Domain crates invoke the macro with a common: [...] list of pre-canned variants and their own domain-specific variants underneath.

use systemprompt_models::domain_error;

domain_error! {
    pub enum FilesError {
        common: [repository, io, json, validation, not_found],

        #[error("permission denied: {path}")]
        PermissionDenied { path: String },
    }
}

The repository token funnels database errors through the canonical systemprompt_database::RepositoryError rather than sqlx::Error directly, so the layer boundary is preserved.