Skip to content

Add typed errors and gRPC status code conversion#227

Open
Vikramarjuna wants to merge 1 commit intoCloud-Foundations:masterfrom
Vikramarjuna:grpc-errors
Open

Add typed errors and gRPC status code conversion#227
Vikramarjuna wants to merge 1 commit intoCloud-Foundations:masterfrom
Vikramarjuna:grpc-errors

Conversation

@Vikramarjuna
Copy link

Add Typed Errors and gRPC Status Code Conversion

Why

Introduce typed errors so that errors returned with proper types can be handled better by callers. This enables:

  • Programmatic error handling (e.g., errors.As(err, &NotFoundError{}))
  • Automatic gRPC status code mapping without string parsing
  • Clearer error messages with structured context (resource, ID, reason)

Existing code can continue using string-based errors - ErrorToStatus() includes pattern matching as a fallback. New code should gradually adopt typed errors.

What

  • lib/errors/types.go: Typed errors implementing CodedError interface (NotFoundError, PermissionDeniedError, InvalidArgumentError, etc.)
  • lib/srpc/errors.go: ErrorToStatus() function for converting errors to gRPC status codes

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