Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#9462·grpc-go

xds/clients: export sentinel errors and preserve error chains via Unwrap()

Author: dashpoleCreated Sep 30, 2026Updated Sep 30, 2026

Use case(s) - what problem will this feature solve?

In internal/xds/clients/xdsclient:

  1. internal/xdsresource/errors.go defines xdsClientError{t ErrorType, desc string} without an Unwrap() method, and authority.go formats underlying stream errors into strings via fmt.Sprintf(..., "%v", err).
  2. External consumers cannot import internal/xdsresource to inspect ErrorType (for example, to distinguish ErrorTypeResourceNotFound when an optional resource does not exist after watch expiry from ErrorTypeConnection when the ADS stream fails), and errors.Is / errors.As / status.FromError(err) fail because the underlying error chain is discarded.

Proposed Solution

  1. Export standard sentinel errors in xdsclient:
    go
    var (
        ErrResourceNotFound = errors.New("xds: resource not found")
        ErrConnection       = errors.New("xds: connection error")
        ErrNACKed           = errors.New("xds: resource NACKed")
    )
  2. Preserve the underlying cause inside xdsClientError and implement Unwrap() []error (wrapping both the sentinel error and the underlying transport/decode error) so callers can use standard errors.Is(err, xdsclient.ErrResourceNotFound) and status.FromError(err).

Alternatives Considered

Exporting the ErrorType enum and ErrType(err) helper function. Standard sentinel errors with Unwrap() integrate directly with the Go standard library's errors.Is and errors.As without requiring a custom error inspection helper.

Additional Context

Part of #9455.

Source: grpc/grpc-go

View original on GitHubView discussion on GitHub