Skip to content

Consider using typed throws on methods that always throw ClientError/ServerError #844

Open

Description

@czechboy0

Consider using typed throws on methods that always throw ClientError/ServerError.

This will allow adopters to remove an extra } catch { that doesn't have clear purpose.

do {
    _ = try await try await client.getGreeting(input: ...)
} catch as ClientError {
    // This branch is always taken
} catch {
    // This branch is never taken, we always throw ClientError
}

Similar on the server.

With typed throws, we'll be able to do:

do {
    _ = try await try await client.getGreeting(input: ...)
} catch {
    // This branch is always taken and error is statically known to be ClientError
}

Activity

  1. simonjbeaumont commented on Nov 8, 2025

    @simonjbeaumont
    Collaborator

    If we're gonna investigate having user handlers be typed throws we might consider enforcing that any error thrown out of the handler is convertible to HTTP status. We discussed this as an alternative direction when discussing the error handling middleware.

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

    area/generatorAffects: plugin, CLI, config file.area/runtimeAffects: the runtime library.kind/enhancementImprovements to existing feature.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions