Skip to content

Use Bad Request status for InputCoercionException #18161

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

Merged
merged 3 commits into from
May 5, 2025

Conversation

dbwiddis
Copy link
Member

@dbwiddis dbwiddis commented Apr 30, 2025

Description

The Jackson InputCoercionException is thrown for a "valid but incompatible input value"

Exception type for read-side problems that are not direct decoding ("parsing") problems (those would be reported as JsonParseExceptions), but rather result from failed attempts to convert specific Java value out of valid but incompatible input value. One example is numeric coercions where target number type's range does not allow mapping of too large/too small input value.

As an exception caused by user input, a 400 (Bad Request) REST status is appropriate. Currently parsing XContent that encounters this error (such as an integer out of range) returns an inappropriate 500 status.

Related Issues

One of two problems reported in #18131

Check List

  • Functionality includes testing.
  • [ ] API changes companion pull request created, if applicable.
  • [ ] Public documentation issue/PR created, if applicable.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@dbwiddis dbwiddis requested a review from a team as a code owner April 30, 2025 03:07
Copy link
Contributor

❌ Gradle check result for afa975d: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Copy link
Contributor

✅ Gradle check result for afa975d: SUCCESS

Copy link

codecov bot commented Apr 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 72.57%. Comparing base (4c2d043) to head (39198e8).
Report is 4 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main   #18161      +/-   ##
============================================
+ Coverage     72.54%   72.57%   +0.03%     
- Complexity    67234    67275      +41     
============================================
  Files          5476     5476              
  Lines        310444   310449       +5     
  Branches      45120    45122       +2     
============================================
+ Hits         225211   225320     +109     
- Misses        66834    66840       +6     
+ Partials      18399    18289     -110     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dbwiddis dbwiddis changed the title Use Bad Request status for InputCoercionEcception Use Bad Request status for InputCoercionException Apr 30, 2025
@andrross
Copy link
Member

Could we add a rest spec test that tests the end-to-end behavior with invalid input? Similar to something like this:

- match: { items.0.index.status: 400 }
- match: { items.0.index.error.type: illegal_argument_exception }

@prudhvigodithi
Copy link
Member

Thanks @dbwiddis LGTM, once we have the rest test we can get this PR in.

@dbwiddis dbwiddis added the v3.1.0 label May 1, 2025
Copy link
Contributor

github-actions bot commented May 1, 2025

❌ Gradle check result for 4c0edc8: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Copy link
Contributor

github-actions bot commented May 4, 2025

❌ Gradle check result for 54e2c95: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Copy link
Contributor

github-actions bot commented May 4, 2025

❌ Gradle check result for 54e2c95: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Copy link
Contributor

github-actions bot commented May 4, 2025

❌ Gradle check result for 54e2c95: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Copy link
Contributor

github-actions bot commented May 4, 2025

❌ Gradle check result for 80801cf: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Copy link
Contributor

github-actions bot commented May 4, 2025

❌ Gradle check result for 0719867: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Signed-off-by: Daniel Widdis <[email protected]>
Copy link
Contributor

github-actions bot commented May 5, 2025

❌ Gradle check result for 971cce6: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@dbwiddis
Copy link
Member Author

dbwiddis commented May 5, 2025

Failing on the Mixed cluster Yaml test because the old nodes don't have the fix...

Signed-off-by: Daniel Widdis <[email protected]>
Copy link
Contributor

github-actions bot commented May 5, 2025

❌ Gradle check result for 39198e8: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Copy link
Contributor

github-actions bot commented May 5, 2025

✅ Gradle check result for 39198e8: SUCCESS

@dbwiddis
Copy link
Member Author

dbwiddis commented May 5, 2025

@prudhvigodithi @andrross ready for re-review. You may want to peek at #18194 as well.

@andrross andrross merged commit 4ce638c into opensearch-project:main May 5, 2025
30 checks passed
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.19 failed:

The process '/usr/bin/git' failed with exit code 128

To backport manually, run these commands in your terminal:

# Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/OpenSearch/backport-2.19 2.19
# Navigate to the new working tree
pushd ../.worktrees/OpenSearch/backport-2.19
# Create a new branch
git switch --create backport/backport-18161-to-2.19
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 4ce638c06fe5a937bee30321f3c609927089de16
# Push it to GitHub
git push --set-upstream origin backport/backport-18161-to-2.19
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/OpenSearch/backport-2.19

Then, create a pull request where the base branch is 2.19 and the compare/head branch is backport/backport-18161-to-2.19.

@peterzhuamazon
Copy link
Member

peterzhuamazon commented May 5, 2025

Hi @dbwiddis you might need to manually backport 2.19.

Thanks.

dbwiddis added a commit to dbwiddis/OpenSearch that referenced this pull request May 5, 2025
…#18161)

* Use Bad Request status for InputCoercionException

Signed-off-by: Daniel Widdis <[email protected]>

* Add yamlRestTest for the fix

Signed-off-by: Daniel Widdis <[email protected]>

* Skip test before 3.1.0

Signed-off-by: Daniel Widdis <[email protected]>

---------

Signed-off-by: Daniel Widdis <[email protected]>
Co-authored-by: opensearch-trigger-bot[bot] <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com>
(cherry picked from commit 4ce638c)
andrross pushed a commit that referenced this pull request May 6, 2025
…8161) (#18203)

* Use Bad Request status for InputCoercionException (#18161)

* Use Bad Request status for InputCoercionException

Signed-off-by: Daniel Widdis <[email protected]>

* Add yamlRestTest for the fix

Signed-off-by: Daniel Widdis <[email protected]>

* Skip test before 3.1.0

Signed-off-by: Daniel Widdis <[email protected]>

---------

Signed-off-by: Daniel Widdis <[email protected]>
Co-authored-by: opensearch-trigger-bot[bot] <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com>
(cherry picked from commit 4ce638c)

* Update CHANGELOG.md

Co-authored-by: Owais Kazi <[email protected]>
Signed-off-by: Daniel Widdis <[email protected]>

---------

Signed-off-by: Daniel Widdis <[email protected]>
Co-authored-by: opensearch-trigger-bot[bot] <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com>
Co-authored-by: Owais Kazi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants