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
57
58
59
60
61
62
63
// Copyright (C) 2026 Kan-Ru Chen <kanru@kanru.info>
//
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//! `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`](crate::Error) with [`expect_error`]:
//!
//! ```
//! use scoped_error::{Error, expect_error};
//! # fn internal() -> Result<(), Error> { Ok(()) }
//!
//! 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 internal() -> Result<(), MyError> { Ok(()) }
//!
//! 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`]
pub use expect_error;
pub use expect_error_fn;
pub use Error;
pub use Frame;
pub use WithContext;
pub use ErrorExt;
pub use Many;
pub use ErrorReport;