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

More explicit error on empty JSON bodies #459

Merged
merged 3 commits into from
Feb 14, 2023
Merged

More explicit error on empty JSON bodies #459

merged 3 commits into from
Feb 14, 2023

Conversation

akshayjshah
Copy link
Member

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.
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")
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Member Author

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.

@akshayjshah akshayjshah merged commit dfa669e into main Feb 14, 2023
@akshayjshah akshayjshah deleted the ajs/json-errors branch February 14, 2023 18:43
renovate bot referenced this pull request in open-feature/flagd Feb 16, 2023
[![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
[@&#8203;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
[@&#8203;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>
akshayjshah added a commit that referenced this pull request Jul 26, 2023
Return a more understandable error when the JSON codec attempts to
unmarshal an empty body.

Fixes #452.
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.

Unexpected errors on empty HTTP request bodies
3 participants