Expand description
Error types for drasi-lib Error types for drasi-lib operations.
This module provides structured error types using thiserror for idiomatic Rust error handling.
The pattern follows major Rust libraries like tokio, reqwest, and sqlx.
§Error Handling Architecture
drasi-lib uses a three-layer error strategy:
| Layer | Error Type | When to Use |
|---|---|---|
| Public API | crate::error::Result<T> / DrasiError | Methods on DrasiLib, *_ops modules, InspectionAPI |
| Internal modules | anyhow::Result<T> | Lifecycle, managers, component_graph — use .context() for rich chains |
| Plugin traits | anyhow::Result<T> | Source, Reaction, BootstrapProvider trait methods |
§Bridge: Internal → Public
DrasiError::Internal(#[from] anyhow::Error) auto-converts internal anyhow errors
at the public API boundary via the ? operator. For errors with known semantics, use
the structured variants directly (e.g., DrasiError::invalid_state()).
§Rules
- Public API methods must return
crate::error::Result<T>withDrasiErrorvariants - Internal modules should use
anyhow::Resultwith.context("what failed") - Plugin trait implementations should use
anyhow::Resultwith.context() - Never use
anyhow!()in public API methods — useDrasiErrorconstructors
§Example
ⓘ
use drasi_lib::error::{DrasiError, Result};
fn example() -> Result<()> {
// Pattern match on specific error variants
match some_operation() {
Err(DrasiError::ComponentNotFound { component_type, component_id }) => {
println!("{} '{}' not found", component_type, component_id);
}
Err(DrasiError::InvalidState { message }) => {
println!("Invalid state: {}", message);
}
Err(e) => return Err(e),
Ok(v) => { /* ... */ }
}
Ok(())
}Enums§
- Drasi
Error - Main error type for drasi-lib operations.
Type Aliases§
- Result
- Result type for drasi-lib operations.