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:
internal/xdsresource/errors.godefinesxdsClientError{t ErrorType, desc string}without anUnwrap()method, andauthority.goformats underlying stream errors into strings viafmt.Sprintf(..., "%v", err).- External consumers cannot import
internal/xdsresourceto inspectErrorType(for example, to distinguishErrorTypeResourceNotFoundwhen an optional resource does not exist after watch expiry fromErrorTypeConnectionwhen the ADS stream fails), anderrors.Is/errors.As/status.FromError(err)fail because the underlying error chain is discarded.
Proposed Solution
- Export standard sentinel errors in
xdsclient:var ( ErrResourceNotFound = errors.New("xds: resource not found") ErrConnection = errors.New("xds: connection error") ErrNACKed = errors.New("xds: resource NACKed") ) - Preserve the underlying cause inside
xdsClientErrorand implementUnwrap() []error(wrapping both the sentinel error and the underlying transport/decode error) so callers can use standarderrors.Is(err, xdsclient.ErrResourceNotFound)andstatus.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