Error2
English | 简体中文
Error handling library with backtrace support and ergonomic error conversion.
Installation
[]
= "0.13.2"
Usage
Define Error Types
Error2 supports three types of errors based on field structure:
1. Root Error - Only backtrace field (new error source)
use *;
2. Standard Error - source + backtrace (wraps std::error::Error)
use *;
3. Error2 Chain - Only source field (chains another Error2 type, reuses its backtrace)
use *;
Convert Errors
// Result<T, Source> -> Result<T, Target>
read_to_string
.context?;
// Option<T> -> Result<T, E>
database.get
.context?;
// E -> Result<T, E>
some_error.context
Note: Helper struct fields are generic with Into trait bounds, so you don't need to call .into() manually. For expensive conversions, use .with_context() instead:
// Lazy evaluation - only converts on error
read
.with_context?;
Track Propagation
Create Root Errors
Use Type-Erased Errors
Print Error Stack
For more details, see API Documentation
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.