From dae7ca4688a33176f1adde924e2544246ef2099b Mon Sep 17 00:00:00 2001 From: Liang Xu <24490353+lx3133584@users.noreply.github.com> Date: Fri, 20 Nov 2026 12:55:06 +0800 Subject: [PATCH] fix(core): keep the cause of a persisted deterministic error A fatal store error reached the operator as `Failed to transact block operations` alone. `detail()` wraps the cause in an `anyhow::Error`, and `ProcessingError::Deterministic` rendered it with `{0}`; the runner then formats the whole enum with `{:#}` for persistence, so `anyhow`'s alternate formatting stopped at the display message instead of walking into the source chain. The diagnostic that identifies the store problem, such as `synthetic constraint violation`, was discarded before it was written. The variant now renders with `{0:#}`. Those `Display` impls that ignore the alternate are unaffected, and `StoreError::Unknown` already formats its cause that way. --- core/src/subgraph/error.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/core/src/subgraph/error.rs b/core/src/subgraph/error.rs index 00413acb258..6fbfe80c2c5 100644 --- a/core/src/subgraph/error.rs +++ b/core/src/subgraph/error.rs @@ -51,7 +51,10 @@ pub enum ProcessingError { // The error had a deterministic cause but, for a possibly non-deterministic reason, we chose to // halt processing due to the error. - #[error("{0}")] + // The runner persists this variant with `{:#}`, so the renderer has to + // keep the alternates reaching the cause. `{0}` alone would print only the + // outermost anyhow message and drop the store diagnostic under it. + #[error("{0:#}")] Deterministic(Box), /// A possible blockchain reorganization was detected. @@ -189,3 +192,26 @@ impl ClassifyErrorHelper for Result { }) } } + +#[cfg(test)] +mod tests { + use super::*; + + /// The runner formats the whole enum with `{:#}` when it persists a fatal + /// error, so that rendering is what an operator ends up reading. A + /// deterministic error that arrives already classified still has to show + /// the store diagnostic under the transaction context; otherwise the + /// message says only that transacting failed. + #[test] + fn a_deterministic_error_keeps_its_cause_under_the_context() { + let store: ProcessingError = + ProcessingError::Deterministic(Box::new(anyhow!("synthetic constraint violation"))); + + let detailed = store.detail("Failed to transact block operations"); + + assert_eq!( + format!("{detailed:#}"), + "Failed to transact block operations: synthetic constraint violation" + ); + } +}