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
//! Task-local error context propagation.
//!
//! Provides [`ErrorContext`] for storing request-scoped metadata (request ID,
//! actor ID, tenant ID) in a task-local variable. This allows error handling
//! code anywhere in the call stack to access contextual information without
//! passing it through every function signature.
use RefCell;
/// Request-scoped context for error enrichment.
///
/// # Examples
///
/// ```
/// use secure_errors::context_propagation::{ErrorContext, set_error_context, get_error_context, clear_error_context};
///
/// let ctx = ErrorContext {
/// request_id: Some("req-123".to_string()),
/// actor_id: Some("user-42".to_string()),
/// tenant_id: None,
/// };
/// set_error_context(ctx);
/// assert!(get_error_context().is_some());
/// clear_error_context();
/// assert!(get_error_context().is_none());
/// ```
thread_local!
/// Sets the error context for the current task/thread.
/// Retrieves a clone of the current error context, if set.
/// Clears the error context for the current task/thread.