Skip to content

Fallible services should be more explicit #2615

Open
@Kestrer

Description

@Kestrer

In Hyper, all services that service HTTP requests are currently fallible with any error type that implements Into<Box<dyn Error + Send + Sync>>. However, accepting such a general type makes it prone to mistakes. Usually, servers want to avoid not sending a response, but it can be very easy to accidentally do so with this lax bound. In particular, it would be nice if we could model things like 404 responses as service errors in Axum, but that makes it really easy to accidentally create a service that aborts the connection on a single 404 instead of gracefully sending a response. Additionally, the bound requires that an error type be explicitly chosen for services that don't ever return an error (i.e. most of them), leading to an extra turbofish and Infallible.

Instead, I propose that Hyper only supports services that have AbortConnection as their error type. This type will either be a unit struct or wrap a BoxError. While it would still support services being able to abort the connection if they wish, it is now a lot harder to accidentally do so and requires explicit consent by the user.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-serverArea: server.B-rfcBlocked: More comments would be useful in determine next steps.C-featureCategory: feature. This is adding a new feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions