Skip to main content

Module error

Module error 

Source
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:

LayerError TypeWhen to Use
Public APIcrate::error::Result<T> / DrasiErrorMethods on DrasiLib, *_ops modules, InspectionAPI
Internal modulesanyhow::Result<T>Lifecycle, managers, component_graph — use .context() for rich chains
Plugin traitsanyhow::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> with DrasiError variants
  • Internal modules should use anyhow::Result with .context("what failed")
  • Plugin trait implementations should use anyhow::Result with .context()
  • Never use anyhow!() in public API methods — use DrasiError constructors

§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§

DrasiError
Main error type for drasi-lib operations.

Type Aliases§

Result
Result type for drasi-lib operations.