0Pricing
gRPC & High Performance APIs · Lesson

Rich Error Models with google.rpc.Status

Go beyond plain status codes by attaching structured, machine-readable error details using the google.rpc.Status model and standard error detail types.

Rich Error Models with google.rpc.Status is a free gRPC & High Performance APIs lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the gRPC & High Performance APIs learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Limits of Plain Status Codes

A bare status code plus a message tells the client that something failed, but not the structured why. Clients often need field-level validation errors, retry hints, or quota info.

The rich error model attaches structured details to a status.

The google.rpc.Status Message

The core type is google.rpc.Status with three fields:

  • code: a numeric status code
  • message: developer-facing text
  • details: a repeated list of Any payloads

Standard Detail Types

Google defines reusable detail messages in google/rpc/error_details.proto:

  • BadRequest — field violations
  • RetryInfo — when to retry
  • QuotaFailure — limit exceeded
  • ErrorInfo — machine-readable reason

BadRequest for Validation

BadRequest carries a list of FieldViolation entries, each naming a bad field and describing the problem. Perfect for form validation responses.

Building a Rich Error in Go

The status package lets you create a status and append typed details with WithDetails.

st := status.New(codes.InvalidArgument, 'invalid request')
v := &errdetails.BadRequest_FieldViolation{
  Field: 'email', Description: 'must be a valid address',
}
br := &errdetails.BadRequest{FieldViolations: []*errdetails.BadRequest_FieldViolation{v}}
st, _ = st.WithDetails(br)
return st.Err()

RetryInfo for Backoff Hints

For temporary failures, attach RetryInfo with a retry_delay. A well-behaved client reads this and waits before retrying.

ri := &errdetails.RetryInfo{RetryDelay: durationpb.New(2 * time.Second)}
st, _ = status.New(codes.Unavailable, 'busy').WithDetails(ri)

ErrorInfo for Stable Reasons

ErrorInfo gives a stable reason string and a domain plus metadata. Unlike free-text messages, clients can branch on these reliably.

ei := &errdetails.ErrorInfo{
  Reason: 'EMAIL_TAKEN', Domain: 'auth.example.com',
}

Reading Details on the Client

The client converts the returned error back to a status and inspects each detail with a type switch.

st := status.Convert(err)
for _, d := range st.Details() {
  switch t := d.(type) {
  case *errdetails.BadRequest:
    handleFieldErrors(t)
  case *errdetails.RetryInfo:
    waitThenRetry(t.RetryDelay)
  }
}

How Details Travel

Details are serialized into the grpc-status-details-bin trailer as a binary Status proto. Languages with the rich-error libraries decode it automatically.

Best Practices

Use the rich model wisely:

  • Prefer standard detail types for interoperability
  • Never leak secrets in messages or details
  • Keep ErrorInfo.reason values stable and documented
  • Pair RetryInfo with truly retryable codes

Cross-Language Interop

Because the model is defined in protobuf, a Go server can emit a BadRequest that a Java or Python client decodes identically. This consistency is the whole point of the standard types.

Quick Check

Test your rich error knowledge.

Recap

You learned the rich error model:

  • google.rpc.Status carries code, message, and repeated detail Any payloads
  • Standard types: BadRequest, RetryInfo, QuotaFailure, ErrorInfo
  • Build with WithDetails, read with a type switch over Details()
  • Details travel in the grpc-status-details-bin trailer
  • Standard types give cross-language consistency

Frequently asked questions

Is the “Rich Error Models with google.rpc.Status” lesson free?

Yes — the full text of “Rich Error Models with google.rpc.Status” is free to read here on the web, and the gRPC & High Performance APIs course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the gRPC & High Performance APIs course, upgrade to CoddyKit PRO.

What will I learn in “Rich Error Models with google.rpc.Status”?

Go beyond plain status codes by attaching structured, machine-readable error details using the google.rpc.Status model and standard error detail types. You practise gRPC & High Performance APIs with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start gRPC & High Performance APIs?

No prior experience is required. gRPC & High Performance APIs on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Rich Error Models with google.rpc.Status” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this gRPC & High Performance APIs lesson?

Yes. Every gRPC & High Performance APIs lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Status Codes and Error Handling
  2. Custom Metadata Transmission
  3. Context and Deadlines
  4. Rich Error Models with google.rpc.Status
← Back to gRPC & High Performance APIs