Skip to content

refactor(error): rename Kind to ErrorKind and update related error ha…#2645

Open
yangfa-zhang wants to merge 1 commit into
grpc:masterfrom
yangfa-zhang:feature/public-err-type
Open

refactor(error): rename Kind to ErrorKind and update related error ha…#2645
yangfa-zhang wants to merge 1 commit into
grpc:masterfrom
yangfa-zhang:feature/public-err-type

Conversation

@yangfa-zhang
Copy link
Copy Markdown

feat(transport): expose ErrorKind for programmatic error discrimination (#2563)

The internal Kind enum that classifies transport::Error variants was
pub(crate), leaving tonic::transport::Error opaque to downstream users:
there was no way to programmatically distinguish a transport-level failure
from an invalid URI, an invalid user-agent header, or a TLS-on-UDS
misconfiguration without parsing Display output or downcasting source().

Changes:

  • Rename Kind to ErrorKind and make it pub, with #[non_exhaustive]
    so future variants can be added without a breaking change.
  • Derive Clone, Copy, Debug, PartialEq, Eq, Hash on ErrorKind (all
    variants are dataless), matching the style of CompressionEncoding.
  • Add a public Error::kind(&self) -> ErrorKind accessor.
  • Re-export ErrorKind from tonic::transport.
  • Add unit tests covering each variant and the Copy bound.

Downstream consumers can now write:

  match err.kind() {
      ErrorKind::InvalidUri => /* ... */,
      ErrorKind::Transport => /* ... */,
      _ => /* required because #[non_exhaustive] */,
  }

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