Skip to content

Preserve error classes across the gRPC transport - #20

Open
vvoland wants to merge 1 commit into
moby:mainfrom
vvoland:maperrors
Open

vvoland wants to merge 1 commit into
moby:mainfrom
vvoland:maperrors

Conversation

@vvoland

@vvoland vvoland commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Errors from out-of-process providers arrived without their errdefs class, so checks such as IsNotFound failed where they succeeded in process.

Generated wiring now encodes the outermost supported class as a gRPC status code and restores the errdefs marker or context sentinel on the other side, including for stream errors. Decoded errors keep the original status, and their message no longer has the "rpc error: code = ... desc = ..." prefix.

containerd's errgrpc is not used: its ToNative drops the gRPC status, and it sends Conflict() as codes.FailedPrecondition, recovered only by matching the message.

Errors from out-of-process providers arrived without their errdefs
class, so checks such as IsNotFound failed where they succeeded in
process.

Generated wiring now encodes the outermost supported class as a gRPC
status code and restores the errdefs marker or context sentinel on the
other side, including for stream errors.
Decoded errors keep the original status, and their message no longer has
the "rpc error: code = ... desc = ..." prefix.

containerd's errgrpc is not used: its ToNative drops the gRPC status,
and it sends Conflict() as codes.FailedPrecondition, recovered only by
matching the message.

Signed-off-by: Paweł Gronowski <git@grono.dev>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A non-comparable error that returns itself through As bypasses the progress guard, causing classCode to loop forever and leaving the generated RPC handler spinning.

1 open issue
4 files not reviewed
  • cmd/mobyextgen/wire.go: Generated file
  • example/greeter/v0/protogen/wire.gen.go: Generated file
  • internal/launcher/echo/v1/protogen/wire.gen.go: Generated file
  • sdk/sdkapi/protogen/wire.gen.go: Generated file
What changed in this PR

This PR preserves supported error classes across gRPC so callers can classify out-of-process provider errors consistently with in-process errors.

Changes:

  • Adds grpcerror conversions that map error classes to status codes and restore markers or context sentinels while retaining status information.
  • Updates generated unary and streaming adapters to apply these conversions.
  • Adds conversion and runtime tests and documents the transport behavior.
File Description
sdk/​sdkapi/​protogen/​wire.gen.go Applies error conversion to SDK RPCs.
internal/​launcher/​echo/​v1/​protogen/​wire.gen.go Applies error conversion to Echo RPCs.
grpcerror/​grpcerror.go Implements error-class encoding and decoding.
grpcerror/​grpcerror_test.go Tests class mappings, precedence, and status preservation.
example/​greeter/​v0/​protogen/​wire.gen.go Applies error conversion to Greeter RPCs.
docs/​DESIGN.md Documents error-class transport semantics.
cmd/​mobyextgen/​wire.go Generates conversions for unary and streaming adapters.
cmd/​mobyextgen/​testdata/​runtime_behavior_test.go.txt Tests class restoration across RPC types and cancellation identity.

Review effort: Balanced

Comment thread grpcerror/grpcerror.go
Comment on lines +221 to +222
if v := reflect.ValueOf(cause); v.Comparable() && cause == err {
return nil
@thaJeztah

Copy link
Copy Markdown
Member

Hm.. so, slightly wondering if we should still consider using github.com/containerd/errdefs (ToNative, or what's it?); would there be a risk for things getting out of sync, not aligning?

Brief LLM summary;

The main differences seem to be that the local implementation preserves the original gRPC status (which containerd's errgrpc.ToNative drops), and handles Conflict errors differently. Containerd maps Conflict to FailedPrecondition and relies on message matching for the reverse conversion.

Both seem like improvements worth considering upstream in containerd, rather than maintaining a separate implementation here.

@vvoland

vvoland commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator Author

We could do that, the differences in behavior are probably edgy and not that important. I don't think the fixes would be upstreamable.
The only difference is errdefs brings-in more code and puts it in the dependency tree.

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.

3 participants