fix(grpcutil): resolve ambiguous code-only error mappings conservatively - #401
Open
ez-lbz wants to merge 3 commits into
Open
fix(grpcutil): resolve ambiguous code-only error mappings conservatively#401ez-lbz wants to merge 3 commits into
ez-lbz wants to merge 3 commits into
Conversation
FromGRPCError falls back to code-only matching when a gRPC status has no ErrorInfo reason. The old fallback took the first mapping matching the code from the full table, which mis-maps codes shared by several a2a errors (e.g. FailedPrecondition -> ErrTaskNotCancelable even when the real error was ErrUnsupportedOperation or ErrExtendedCardNotConfigured). When no reason is present, use the single mapping when exactly one error exists for the code, otherwise fall back to the conservative ErrInternalError instead of guessing. Reason-based matching is unchanged and takes priority. Add regression tests for the fallback and for reason priority.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
1. Resolve ambiguous code-only gRPC error mappings conservatively
Problem:
When a gRPC status carries no
ErrorInforeason,FromGRPCErrormatched by code alone and picked the first mapping for that code. Several a2a errors share a gRPC code (e.g.FailedPreconditionmaps toErrTaskNotCancelable,ErrUnsupportedOperation, ...), so the picked error could be the wrong one.Fix (internal/grpcutil/errors.go, internal/grpcutil/errors_test.go):
a2a.ErrInternalErrorinstead of guessing.ErrorInforeason still takes priority over the code-only fallback.TestFromGRPCErrorCodeOnlyFallbackandTestFromGRPCErrorReasonPriority.Testing
go test ./internal/grpcutil/ ./a2agrpc/... ./a2aclient/...— all pass.Behavior change: code-only errors for codes shared by several a2a errors now map to
ErrInternalErrorinstead of an arbitrary one; single-candidate and reason-based mappings are unchanged.