Skip to content

Conversation

i2y
Copy link
Contributor

@i2y i2y commented Oct 3, 2025

This PR adds error handling documentation covering error codes, client/server examples, error details, and best practices.

@i2y i2y force-pushed the docs/error-handling branch 2 times, most recently from 6136ab2 to 21f3980 Compare October 4, 2025 01:29
i2y added 4 commits October 4, 2025 12:12
Signed-off-by: i2y <6240399+i2y@users.noreply.github.com>
Signed-off-by: i2y <6240399+i2y@users.noreply.github.com>
Signed-off-by: i2y <6240399+i2y@users.noreply.github.com>
Signed-off-by: i2y <6240399+i2y@users.noreply.github.com>
@i2y i2y force-pushed the docs/error-handling branch from 9b73ddf to a7bd90b Compare October 4, 2025 03:14
Signed-off-by: i2y <6240399+i2y@users.noreply.github.com>
@i2y i2y marked this pull request as ready for review October 4, 2025 03:43
docs/errors.md Outdated
Comment on lines 166 to 180
```json
HTTP/1.1 400 Bad Request
Content-Type: application/json

{
"code": "invalid_argument",
"message": "name is required",
"details": [
{
"type": "google.protobuf.Struct",
"value": "base64-encoded-protobuf"
}
]
}
```
Copy link
Member

Choose a reason for hiding this comment

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

nit: not sure if http is a valid markdown language tag, but could be more appropriate here if it is. (although then maybe the json wouldn't be pretty 😞.)

can probably just ignore this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I changed json to http now

Comment on lines +167 to +172
Select error codes that accurately reflect the situation:

- Use `INVALID_ARGUMENT` for malformed requests that should never be retried
- Use `FAILED_PRECONDITION` for requests that might succeed if the system state changes
- Use `UNAVAILABLE` for transient failures that should be retried
- Use `INTERNAL` sparingly - it indicates a bug in your code
Copy link
Member

Choose a reason for hiding this comment

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

I might link to https://connectrpc.com/docs/protocol#error-codes; the discussion below the table about how to choose an error code is pretty useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, thanks! I just wrote the link below.

violation = bad_request.field_violations.add()
violation.field = field
violation.description = error
raise ConnectError(Code.INVALID_ARGUMENT, "Validation failed", details=[bad_request])
Copy link
Member

Choose a reason for hiding this comment

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

my only hesitation on recommending error details is that in practice, they can make it more difficult to debug if your client isn't already deserializing them. And there's no way to strongly enforce them in your API contract; the best you can really do is just document them.

I think this is fine to leave as-is, just wish error details were easier to use in general.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this PR is trying to match the coverage of Go docs which similarly cover error details so is probably good as is. Agree that error details are a bit clunky but too useful for substituting for custom error codes to leave out.

Copy link
Contributor Author

@i2y i2y Oct 5, 2025

Choose a reason for hiding this comment

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

Signed-off-by: i2y <6240399+i2y@users.noreply.github.com>
@i2y i2y requested review from anuraaga and stefanvanburen October 5, 2025 10:07
@i2y i2y merged commit 668f39f into main Oct 6, 2025
23 checks passed
@i2y i2y deleted the docs/error-handling branch October 6, 2025 03:12
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.

3 participants