client: EncodingBody pairs its error mirror with construction only by convention

Open
#230 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
65/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Quiet
Tech stack
rust
Domain
api

Research direction

Start in connectrpc/src/client/mod.rs at call_client_stream, then locate the EncodingBody construction and its shared error slot. Verify how the slot is drained and how encoding failures reach the caller; done means the pairing is compiler-visible and the existing precise error behavior remains intact.

Written by the indexing model from the issue text.

Description

Problem

EncodingBody reports an encode failure two ways at once: it returns Poll::Ready(Some(Err(..))) through the body (which aborts the request at the transport level) and it stashes the error in a shared Arc<Mutex<Option<ConnectError>>> so the call can surface the precise error instead of the generic transport failure it would otherwise see.

Those two halves are paired by convention only. Nothing makes a construction site drain the mirror — the type system is happy with an EncodingBody whose error slot no caller ever reads, and the symptom would be a confusing unavailable transport error in place of the real encode failure, which is exactly the outcome the slot exists to prevent.

There is one construction site today (call_client_stream in connectrpc/src/client/mod.rs), and it does drain the slot, so this is latent rather than live.

Suggested fix

Make the contract compiler-visible, e.g.:

impl<S> EncodingBody<S> {
    fn new(/* ... */) -> (Self, EncodeErrorSlot) { /* ... */ }
}

with #[must_use] on the returned slot, so a construction site that ignores it warns.

Why this is not in #227

Raised by @lovesegfault as a non-blocking comment on #227. The rest of that review round was documentation, which could be applied without disturbing an already-verified PR; this one is a refactor of the error path and would mean re-running the full battery. Splitting it out keeps that PR's verification intact.

Worth doing before a second construction site appears — that is the point at which the convention starts actually costing something.

Dominant language
Rust
Stars
544
Forks
77
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from connectrpc/connect-rust

All issues in connectrpc/connect-rust

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.