Skip to content

payjoin::io::Error repeats the wrapped error's message in its source chain #2093

Backlog

Description

@xstoicunicornx

payjoin::io::Error shows a wrapped error twice in a source chain.

For a wrapped error (Reqwest, ParseUrl, Io, Rustls), Display prints the inner error's message, and source() returns that same inner error. Anything that walks the chain, such as anyhow's {:#}, prints the message twice:

error sending request for url (...): error sending request for url (...): connection refused

Plain {} avoids the repeat but drops the underlying cause, here "connection refused". So no formatting gives a complete message without the repeat.

This isn't a regression. The code has been this way since at least 9349c7e5 (May 2025). Callers today format these errors with {}, so nobody sees the repeat, but the underlying cause has always been missing from fetch errors.

An error should either include its inner error in Display or return it from source(), not both. The simplest fix is to give each wrapped variant its own short message, such as Self::Reqwest(_) => write!(f, "HTTP request failed"), and keep returning the inner error from source(). Callers that format with {:#} then get the full chain once.

Activity

  1. added
    good first issue
    on Dec 2, 2026
  2. xstoicunicornx commented on Dec 3, 2026

    @xstoicunicornx
    CollaboratorAuthor

    Findings from claude opus 5.5:

    Additional errors with the same issue

    OhttpEncapsulationError: Display and source() in payjoin/src/core/ohttp.rs. The Http, Ohttp, Bhttp and ParseUrl arms print the wrapped message with e.fmt(f) and also return Some(e) from source(). That's the pre-PR io bug.

    HpkeError::Hpke: Display, line 290 and source(), line 310 in payjoin/src/core/hpke.rs. Same pattern.

    Other errors like this

    Many more. A subagent checked every error type in the repo and found 54 variants across 21 types where the message includes the wrapped error's text and source() returns that same error. I opened four of them myself (ohttp.rs:79, send/error.rs:61, uri/v2.rs:271, core/error.rs:14), and the pattern is real in each.

    They come in two forms:

    • Pure copy, the same form as finding 3. The message is just the wrapped error's text, so {:#} prints X: X.
    • Label plus copy. The message is label: {e}, so {:#} prints label: X: X. Option 3 avoids this because its source() skips a level. These variants return Some(e), so they repeat.

    By file, with message line and source() line:

    payjoin, pure copy

    • core/error.rs:14 / :18: ImplementationError. This is the wrapper for errors from users' own callbacks, so it's in many chains.
    • core/hpke.rs:290 / :310: HpkeError::Hpke
    • core/ohttp.rs:190-193 / :203-206: OhttpEncapsulationError (4 variants)
    • core/psbt/mod.rs:330 / :345: InternalPsbtInputError::WeightError
    • core/psbt/mod.rs:372 / :376: PsbtInputError (newtype)
    • core/receive/error.rs:266-269 / :292-295: PayloadError (Utf8, ParsePsbt, SenderParams, InconsistentPsbt)
    • core/receive/v1/error.rs:43 / :53: RequestError::InvalidContentLength
    • core/send/error.rs:309 / :289: ResponseError::WellKnown

    payjoin, label plus copy

    • core/ohttp.rs:79 / :96: DirectoryResponseError::OhttpDecapsulation
    • core/ohttp.rs:372-373 / :384: OhttpKeysError::Decode, Encode
    • core/receive/error.rs:270 / :296: PayloadError::InvalidInputUtxo
    • core/receive/v2/error.rs:38-40 / :50-52: SessionError (ParseUrl, Hpke, DirectoryResponse)
    • core/receive/v2/error.rs:84-85 / :97-98: CreateRequestError (Hpke, OhttpEncapsulation)
    • core/send/error.rs:61-62 / :84-85: BuildSenderError (AddressType, InputWeight)
    • core/send/error.rs:130, 132 / :145, 147: ValidationError (Proposal, V2Decapsulation)
    • core/send/error.rs:195, 197, 198, 221 / :231, 233, 234, 257: InternalProposalError (4 variants)
    • core/send/error.rs:310 / :290: ResponseError::Validation
    • core/send/v2/error.rs:28-29 / :41-42: CreateRequestError (Hpke, OhttpEncapsulation)
    • core/send/v2/error.rs:81-82 / :92-93: DecapsulationError (Hpke, DirectoryResponse)
    • core/uri/error.rs:49-50 / :58-59: UriParseError (Bip21, PayjoinParams)
    • core/uri/v2.rs:271-273 / :283-285: PjParseError (3 variants)
    • core/uri/v2.rs:304-305 / :317-318: ParseOhttpKeysParamError
    • core/uri/v2.rs:339-340 / :351-352: ParseExpParamError
    • core/uri/v2.rs:373-374 / :386-387: ParseReceiverPubkeyParamError
    • directory.rs:54-55 / :63-64: ShortIdError

    Other crates, all label plus copy

    • payjoin-cli/src/db/error.rs:31-36 / :53-58: db::Error (4 variants)
    • payjoin-ffi/src/error.rs:23 / :24: SerdeJsonError (thiserror #[error("...: {0}")] with #[from])
    • payjoin-mailroom/src/db/mod.rs:38-39 / :51-52: db::Error (Operational, Timeout)
    • payjoin-mailroom/src/db/files.rs:542 / :529: files::Error::IO

    Borderline. Nine more variants put the wrapped error's Debug text in the message instead of its normal text (for example send/error.rs:49-50, uri/error.rs:108, 114). With {:#} the same error still appears twice, once in each format.

    Two things stand out:

    • Repeats stack up across layers. Some outer types do skip a level correctly, but the duplicate further down still shows. For example, receive::Error::Protocol leads to PayloadError::Utf8, which still prints the Utf8 text twice.
    • The PR's change won't be visible to most users. Almost every user-facing error in payjoin repeats somewhere in its chain, so fixing only io.rs leaves anyone printing with {:#} still seeing repeats from the other 20 types.
  3. added a commit that references this issue on Dec 4, 2026
    9036d0c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions