Skip to main content

common/
error.rs

1//! Generic error type for tree-walking operations that preserves the partial
2//! summary (work that completed before the error) alongside the error chain.
3//!
4//! Each operation (copy, link, rm, filegen) wraps this with a per-operation
5//! `Summary` via a type alias.
6//!
7//! # Logging Convention
8//! When logging this error, use `{:#}` or `{:?}` format to preserve the error chain:
9//! ```ignore
10//! tracing::error!("operation failed: {:#}", &error); // ✅ Shows full chain
11//! tracing::error!("operation failed: {:?}", &error); // ✅ Shows full chain
12//! ```
13//! The Display implementation also shows the full chain, but workspace linting enforces `{:#}`
14//! for consistency.
15
16#[derive(Debug, thiserror::Error)]
17#[error("{source:#}")]
18pub struct OperationError<S> {
19    #[source]
20    pub source: anyhow::Error,
21    pub summary: S,
22}
23
24impl<S> OperationError<S> {
25    #[must_use]
26    pub fn new(source: anyhow::Error, summary: S) -> Self {
27        OperationError { source, summary }
28    }
29}