-
Notifications
You must be signed in to change notification settings - Fork 108
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
More explicit error on empty JSON bodies #459
Conversation
Return a more understandable error when the JSON codec attempts to unmarshal an empty body. Fixes #452.
codec.go
Outdated
@@ -93,6 +94,9 @@ func (c *protoJSONCodec) Unmarshal(binary []byte, message any) error { | |||
if !ok { | |||
return errNotProto(message) | |||
} | |||
if len(binary) == 0 { | |||
return errors.New("empty string is not a valid JSON object") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we elevate this up to a package level var ErrEmptyBody
or something to make it easier for a user to check like, err == connect.ErrEmptyBody
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this error is still mostly for manual inspection;
it's useful in testing and manual verification if something goes wrong but I don't think clients should ever be sending invalid json and then building error handling around this error because they should check that empty strings aren't sent in the first place
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tend to agree with Josh; I'd like to see a little more evidence that people need programmatic comparison to this error - e.g., they're writing interceptors that handle this case and retry the inner function with a zero-value request message.
Public API is forever, so I'd rather be conservative in adding it.
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [github.com/bufbuild/connect-go](https://togithub.com/bufbuild/connect-go) | require | patch | `v1.5.1` -> `v1.5.2` | --- ### Release Notes <details> <summary>bufbuild/connect-go</summary> ### [`v1.5.2`](https://togithub.com/bufbuild/connect-go/releases/tag/v1.5.2) [Compare Source](https://togithub.com/bufbuild/connect-go/compare/v1.5.1...v1.5.2) <!-- Release notes generated using configuration in .github/release.yml at main --> #### What's Changed ##### Bugfixes - More explicit error on empty JSON bodies by [@​akshayjshah](https://togithub.com/akshayjshah) in [https://github.com/bufbuild/connect-go/pull/459](https://togithub.com/bufbuild/connect-go/pull/459) - Fix string casing for gRPC-Web trailers by [@​timostamm](https://togithub.com/timostamm) in [https://github.com/bufbuild/connect-go/pull/461](https://togithub.com/bufbuild/connect-go/pull/461) **Full Changelog**: bufbuild/connect-go@v1.5.1...v1.5.2 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/open-feature/flagd). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4xMzguMyIsInVwZGF0ZWRJblZlciI6IjM0LjEzOC4zIn0=--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Return a more understandable error when the JSON codec attempts to unmarshal an empty body. Fixes #452.
Return a more understandable error when the JSON codec attempts to
unmarshal an empty body.
Fixes #452.