Skip to content

feat(util): introduce ErrorBody<D, E> - #179

Open
cratelyn wants to merge 2 commits into
masterfrom
error-body
Open

feat(util): introduce ErrorBody<D, E>#179
cratelyn wants to merge 2 commits into
masterfrom
error-body

Conversation

@cratelyn

@cratelyn cratelyn commented Sep 2, 2026

Copy link
Copy Markdown
Member

a common piece of boilerplate code that shows up in test coverage for
body middleware is an "error body". at the time of writing, three such
examples live in the test code for this respository. this commit
introduces a reusable error body to facilitate authoring such test
coverage.

this body yields an error once, and then proceeds to yield Ready(None)
when polled afterwards.

this body exposes a D generic to control the Body::Data frame type,
to permit this to be used in situations with various Buf
implementations.

a common piece of boilerplate code that shows up in test coverage for
body middleware is an "error body". at the time of writing, three such
examples live in the test code for this respository. this commit
introduces a reusable error body to facilitate authoring such test
coverage.

this body yields an error once, and then proceeds to yield `Ready(None)`
when polled afterwards.

this body exposes a `D` generic to control the `Body::Data` frame type,
to permit this to be used in situations with various `Buf`
implementations.

Signed-off-by: katelyn martin <git@katelyn.world>
@cratelyn
cratelyn marked this pull request as ready for review September 2, 2026 17:21
because type inference can get tripped up on the `Body::Data` type, add
an example showing the construction of an error body.

Signed-off-by: katelyn martin <git@katelyn.world>
///
/// This is most often useful for situations like exercising error-handling logic in tests.
#[derive(Debug)]
pub struct ErrorBody<D, E> {

@cratelyn cratelyn Sep 2, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚴 bikeshed: i could see this being called Error, rather than ErrorBody. because std::error::Error is such a foundational type though, and other common types like anyhow::Error and thiserror::Error would also conflict with that, i opted to include the Body suffix.

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