Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error codes #3908

Merged
merged 10 commits into from
Jan 26, 2024
92 changes: 92 additions & 0 deletions daprdocs/content/en/reference/errors/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
---
type: docs
title: Dapr Errors
elena-kolevska marked this conversation as resolved.
Show resolved Hide resolved
linkTitle: "Dapr Errors"
elena-kolevska marked this conversation as resolved.
Show resolved Hide resolved
weight: 700
description: "Information on Dapr errors and how to handle them"
---

# Dapr Error Handling: Understanding the Error Models
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# Dapr Error Handling: Understanding the Error Models
# Error handling: Understanding errors model and reporting

elena-kolevska marked this conversation as resolved.
Show resolved Hide resolved

Initially, Dapr followed the standard gRPC error model. However, to provide more detailed and informative error messages, Dapr is gradually transitioning to a richer error model as defined by gRPC.
elena-kolevska marked this conversation as resolved.
Show resolved Hide resolved

> Not all Dapr errors have been converted to the richer gRPC error model.
elena-kolevska marked this conversation as resolved.
Show resolved Hide resolved

### Standard gRPC Error Model

The [standard gRPC error model](https://grpc.io/docs/guides/error/#standard-error-model) is a straightforward approach to error reporting gRPC. Each error response includes an error code and an error message. The error codes are standardized and reflect common error conditions.
elena-kolevska marked this conversation as resolved.
Show resolved Hide resolved

Example of a Standard gRPC Error Response:
elena-kolevska marked this conversation as resolved.
Show resolved Hide resolved
```
ERROR:
Code: InvalidArgument
Message: input key/keyPrefix 'bad||keyname' can't contain '||'
```

### Richer gRPC Error Model
elena-kolevska marked this conversation as resolved.
Show resolved Hide resolved

The richer error model enhances the standard 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.
elena-kolevska marked this conversation as resolved.
Show resolved Hide resolved


**Example of a Richer gRPC Error Response:**
elena-kolevska marked this conversation as resolved.
Show resolved Hide resolved
```
ERROR:
Code: InvalidArgument
Message: input key/keyPrefix 'bad||keyname' can't contain '||'
Details:
1) {
"@type": "type.googleapis.com/google.rpc.ErrorInfo",
"domain": "dapr.io",
"reason": "DAPR_STATE_ILLEGAL_KEY"
}
2) {
"@type": "type.googleapis.com/google.rpc.ResourceInfo",
"resourceName": "statestore",
"resourceType": "state"
}
3) {
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "bad||keyname",
"description": "input key/keyPrefix 'bad||keyname' can't contain '||'"
}
]
}
```

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.
elena-kolevska marked this conversation as resolved.
Show resolved Hide resolved

**Example of an HTTP Error Response:**
elena-kolevska marked this conversation as resolved.
Show resolved Hide resolved
```json
{
"errorCode": "ERR_MALFORMED_REQUEST",
"message": "api error: code = InvalidArgument desc = input key/keyPrefix 'bad||keyname' can't contain '||'",
"details": [
{
"@type": "type.googleapis.com/google.rpc.ErrorInfo",
"domain": "dapr.io",
"metadata": null,
"reason": "DAPR_STATE_ILLEGAL_KEY"
},
{
"@type": "type.googleapis.com/google.rpc.ResourceInfo",
"description": "",
"owner": "",
"resource_name": "statestore",
"resource_type": "state"
},
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"field_violations": [
{
"field": "bad||keyname",
"description": "api error: code = InvalidArgument desc = input key/keyPrefix 'bad||keyname' can't contain '||'"
}
]
}
]
}
```

You can find the specification of all the possible status details [here](https://github.com/googleapis/googleapis/blob/master/google/rpc/error_details.proto).
Copy link
Member

Choose a reason for hiding this comment

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

This should be moved to after the first paragraph in the enhanced error section above, since this is what people will use to create/understand errors.

Copy link
Contributor Author

@elena-kolevska elena-kolevska Jan 18, 2024

Choose a reason for hiding this comment

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

So switch the order of the grpc and json examples, right? They're the same thing, it's just that we're showing the json representation (used in http connections) and the proto structure for gRPC connections.

Loading