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
//! Backtrace capture and context attachment helpers.
//!
//! Provides utilities for attaching diagnostic context to error reports.
//! Backtrace capture is best-effort — available only when `RUST_BACKTRACE=1`
//! is set in the environment.
/// Captures the current backtrace as a string, if backtraces are enabled.
///
/// Returns `Some(backtrace_string)` when `RUST_BACKTRACE` is set, `None` otherwise.
///
/// # Examples
///
/// ```
/// use secure_errors::capture::capture_backtrace;
///
/// // Returns None when RUST_BACKTRACE is not set.
/// let bt = capture_backtrace();
/// // bt is either Some("...") or None depending on environment.
/// ```
/// Attaches a key-value context entry to an existing cause string.
///
/// This helper appends `key=value` pairs to the internal cause text so that
/// forensic context accumulates on the `ErrorReport` without leaking into
/// the public response.
///
/// # Examples
///
/// ```
/// use secure_errors::capture::attach_context;
///
/// let cause = "query failed";
/// let enriched = attach_context(cause, "table", "users");
/// assert_eq!(enriched, "query failed [table=users]");
/// ```