Skip to content

fix: expose wrapped errors via source() in Method and StatusError variants#1409

Open
zancas wants to merge 1 commit into
fix/1404-send-rejection-maskingfrom
fix/1408-severed-source-chains
Open

fix: expose wrapped errors via source() in Method and StatusError variants#1409
zancas wants to merge 1 commit into
fix/1404-send-rejection-maskingfrom
fix/1408-severed-source-chains

Conversation

@zancas

@zancas zancas commented Jul 16, 2026

Copy link
Copy Markdown
Member

Closes #1408. Stacked on #1405 — the base branch is fix/1404-send-rejection-masking; retarget to dev after #1405 merges. Only the top commit (fix: expose wrapped errors via source() in Method and StatusError variants) belongs to this PR.

Problem

#1404 was caused in part by an error-enum variant carrying its cause in a plain field without #[source], silently severing the source() chain that the serving surfaces downcast-walk to attribute node rejections. PR #1405 fixed the variant that bit (RpcRequestError::UnexpectedErrorResponse); the follow-up audit (#1408) found the same latent pattern in four more places:

  • RpcRequestError::Method(MethodError) in packages/zaino-fetch/src/jsonrpsee/connector.rs — a typed method-specific rejection (and anything it wraps) was unreachable from source() walks.
  • The three StatusError(StatusError) wrapper variants in packages/zaino-state/src/error.rs (MempoolError, NonFinalisedStateError, FinalisedStateError).

Fix

All four variants now mark their payload #[source], preserving the invariant #1405 documented: any variant that wraps another error must expose it via source(), or downstream attribution silently degrades to a generic wrapper message.

The change is smaller than the issue predicted. The issue anticipated bounding the generic (MethodError: std::error::Error), but thiserror infers the required trait bounds per generated impl, so no signature changes were needed anywhere — the whole workspace compiles unchanged.

One deliberate behavior change: because a #[source] payload is a real error with a real message, Method's display switches from Debug to Display formatting (Method error: MissingInputsMethod error: Missing inputs). Nothing in the tree matches on the old format.

Tests (written first, confirmed red, now green)

  1. method_exposes_method_error_via_source (zaino-fetch) pins that Method exposes its payload via source() with the typed method error downcastable.
  2. Three tests in a new status_error_wrappers module (zaino-state), one per wrapper enum, each asserting the wrapped StatusError is reachable and downcastable via source().

All four failed before the fix with source() returning None at the severed link.

Verified with cargo check --workspace --all-targets, cargo clippy --workspace --all-targets (exit zero; only pre-existing live-test warnings), cargo fmt --all, and cargo nextest run on the production set (370/370 green).

🤖 Generated with Claude Code

…iants

Issue #1404 was caused in part by an error-enum variant
that carried its cause in a plain field without `#[source]`, silently
severing the `source()` chain that the serving surfaces downcast-walk
to attribute node rejections. The fix for that issue healed the variant
that bit (`RpcRequestError::UnexpectedErrorResponse`); this commit
closes the remaining structural gaps the follow-up audit found
(#1408).

`RpcRequestError::Method` now marks its payload `#[source]`, keeping
the typed method-specific rejection reachable from `source()` walks.
thiserror infers the required trait bounds per generated impl, so the
generic parameter needs no explicit `std::error::Error` bound and no
call site changes. Because a `#[source]` payload is a real error with a
real message, the variant's display switches from `Debug` to `Display`
formatting; nothing in the tree matched on the old format.

The three `StatusError` wrapper variants — in `MempoolError`,
`NonFinalisedStateError`, and `FinalisedStateError` — likewise gain
`#[source]`; their display strings are unchanged.

Following the test-first order, four regression tests were written and
confirmed red before the fix: one in zaino-fetch pinning that `Method`
exposes its payload via `source()`, and one per wrapper enum in a new
`status_error_wrappers` test module in zaino-state.

Closes #1408.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant