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
//! # Error handling traits
//!
//! ## What
//! This module provides traits for enhancing error handling capabilities,
//! particularly for adding contextual information to errors.
//!
//! ## How
//! The `ErrorContext` trait extends results with methods to add static or
//! dynamic context to errors, making error messages more informative.
//!
//! ## Why
//! Adding context to errors improves debugging and error reporting by providing
//! information about the operation that failed and the circumstances of the failure.
use Result as CoreResult;
use Display;
use ;
/// Error context trait for adding contextual information to errors.
///
/// This trait provides methods to add context to any error that can be converted
/// to our standard Error type, making debugging easier by providing operation context.
///
/// # Examples
///
/// ```
/// use sublime_standard_tools::error::{ErrorContext, FileSystemError, Result};
/// use std::path::PathBuf;
///
/// fn read_project_config() -> Result<String> {
/// let error = FileSystemError::NotFound { path: PathBuf::from("/missing/config.toml") };
/// Err(error)
/// .context("Failed to load project configuration")
/// }
/// ```