Expand description
scoped_error - Context-aware error handling.
This library provides easy error context propagation without requiring
wrapper types at each layer. Context (message + location) is attached
directly to error types that implement WithContext.
§Quick Start
For simple use cases, use scoped_error::Error with expect_error:
use scoped_error::{Error, expect_error};
fn do_work() -> Result<(), Error> {
expect_error("Failed to do something", || {
internal()?;
Ok(())
})
}Use impl_context_error! to create custom context error types:
use scoped_error::{impl_context_error, expect_error};
impl_context_error!(MyError);
fn do_work() -> Result<(), MyError> {
expect_error("Failed to do something", || {
internal()?;
Ok(())
})
}§Core Concepts
- Context propagation: Attach context (message + source location) to errors
- No wrapper types: Context is stored directly in the error type
- Automatic location tracking: Uses
#[track_caller]to capture call sites - Error reports: Format full error chains with
ErrorReport
Macros§
- impl_
context_ error - Implement context-aware error handling for a custom type.
Structs§
- Error
- A convenient, ready-to-use error type with built-in context support.
- Error
Report - A formatted error report.
- Frame
- A single layer of error context.
- Many
- An error type that can have multiple simultaneous causes.
Traits§
- Error
Ext - Extension trait for
std::error::Error. - With
Context - A trait for error types that can carry context information.
Functions§
- expect_
error - Add context to errors, returning a custom error type.
- expect_
error_ fn - Low-level function for adding context with a custom error constructor.