1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//! Cross-module error utilities.
//!
//! If a variant in an agent error type (e.g. [`crate::llm::ProviderError`],
//! [`crate::tool::ToolError`]) needs to propagate an arbitrary `std::error::Error`,
//! **always use [`BoxError`]** instead of a bare
//! `Box<dyn std::error::Error + Send + Sync>`.
//!
//! Using a newtype (rather than a type alias) has these advantages:
//! - Shorter, more readable type signatures
//! - Distinguishes from "any dyn Error" at the type level, making caller intent clearer
//! - Future implementation changes (e.g. switching to `anyhow::Error`, adding backtrace
//! support) require only one change
use Error as StdError;
use fmt;
/// A type-erased error value. Carries an error from any source in a public API without
/// exposing the concrete type.
///
/// Construction:
/// - [`BoxError::new`]: wraps any `E: Error + Send + Sync + 'static`
/// - `From<Box<dyn Error + Send + Sync>>`: migrates from an already-boxed form
///
/// **No** `From<E>` for arbitrary `E: Error`: under Rust's coherence rules, this would
/// overlap with the blanket `From<T> for T` impl (since `BoxError` itself implements
/// `Error`). Callers should use [`BoxError::new`] to wrap explicitly.
;