How does gRPC handle errors?
Answer
gRPC errors are represented by a status containing a StatusCode and an optional message. When an RPC fails, the client receives an error object that wraps these. In Go: st, ok := status.FromError(err); if ok { fmt.Println(st.Code(), st.Message()) }. Servers return errors using the status API: return nil, status.Errorf(codes.NotFound, "user %d not found", id). For richer error details, gRPC supports error details via the google.rpc.Status Protobuf message, which can carry structured error information (field violations, retry info, resource info). The google.rpc package provides standard error detail types: BadRequest with field violations for validation errors, RetryInfo for temporary failures, and ErrorInfo for domain-specific errors. Avoid using UNKNOWN — always use the most specific status code.