Dapr errors

Error handling: Understanding errors model and reporting

Initially, errors followed the Standard gRPC error model. However, to provide more detailed and informative error messages, an enhanced error model has been defined which aligns with the gRPC Richer error model.

Note

Not all Dapr errors have been converted to the richer gRPC error model.

Standard gRPC Error Model

The Standard gRPC error model is an approach to error reporting in gRPC. Each error response includes an error code and an error message. The error codes are standardized and reflect common error conditions.

Example of a Standard gRPC Error Response:

  1. ERROR:
  2. Code: InvalidArgument
  3. Message: input key/keyPrefix 'bad||keyname' can't contain '||'

Richer gRPC Error Model

The Richer gRPC error model extends the standard error model by providing additional context and details about the error. This model includes the standard error code and message, along with a details section that can contain various types of information, such as ErrorInfo, ResourceInfo, and BadRequest details.

Example of a Richer gRPC Error Response:

  1. ERROR:
  2. Code: InvalidArgument
  3. Message: input key/keyPrefix 'bad||keyname' can't contain '||'
  4. Details:
  5. 1) {
  6. "@type": "type.googleapis.com/google.rpc.ErrorInfo",
  7. "domain": "dapr.io",
  8. "reason": "DAPR_STATE_ILLEGAL_KEY"
  9. }
  10. 2) {
  11. "@type": "type.googleapis.com/google.rpc.ResourceInfo",
  12. "resourceName": "statestore",
  13. "resourceType": "state"
  14. }
  15. 3) {
  16. "@type": "type.googleapis.com/google.rpc.BadRequest",
  17. "fieldViolations": [
  18. {
  19. "field": "bad||keyname",
  20. "description": "input key/keyPrefix 'bad||keyname' can't contain '||'"
  21. }
  22. ]
  23. }

For HTTP clients, Dapr translates the gRPC error model to a similar structure in JSON format. The response includes an errorCode, a message, and a details array that mirrors the structure found in the richer gRPC model.

Example of an HTTP error response:

  1. {
  2. "errorCode": "ERR_MALFORMED_REQUEST",
  3. "message": "api error: code = InvalidArgument desc = input key/keyPrefix 'bad||keyname' can't contain '||'",
  4. "details": [
  5. {
  6. "@type": "type.googleapis.com/google.rpc.ErrorInfo",
  7. "domain": "dapr.io",
  8. "metadata": null,
  9. "reason": "DAPR_STATE_ILLEGAL_KEY"
  10. },
  11. {
  12. "@type": "type.googleapis.com/google.rpc.ResourceInfo",
  13. "description": "",
  14. "owner": "",
  15. "resource_name": "statestore",
  16. "resource_type": "state"
  17. },
  18. {
  19. "@type": "type.googleapis.com/google.rpc.BadRequest",
  20. "field_violations": [
  21. {
  22. "field": "bad||keyname",
  23. "description": "api error: code = InvalidArgument desc = input key/keyPrefix 'bad||keyname' can't contain '||'"
  24. }
  25. ]
  26. }
  27. ]
  28. }

You can find the specification of all the possible status details here.


Last modified October 11, 2024: Fixed typo (#4389) (fe17926)