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

fix: This fixes a bug in our RestHelpers that would result into empty string returned from reading a http response content. Which subsequently cause exception while parsing the json #2046

Closed

Conversation

saileshbaidya
Copy link
Contributor

This fixes a bug in our RestHelpers that would result into empty string returned from reading a http response content. Which subsequently cause exception while parsing the json.

Related Issues/PRs

#xxx

What changes are proposed in this pull request?

Issue: There is a bug in RestHelpers.parseResult in calling org.apache.commons.io.IOUtils.toString. There is two problem, first it misses on handling exceptions(NullPointerException, IOException, and UnsupportedCharactersetException) and second is the empty http response content. When this happens we are returning an empty string which does not confirm with json format.

The subsequent parsing throws the following exception.
"spray.json.JsonParser$ParsingException: Unexpected end-of-input at input index 0 (line 1, position 1), expected JSON Value:

^"
Proposed mitigation: Return an empty json "{}" in such situation.

How is this patch tested?

  • I have written tests (not required for typo or doc fix) and confirmed the proposed feature/bug-fix/change works.
  • [*] Manual tests.

Does this PR change any dependencies?

  • [*] No. You can skip this section.
  • Yes. Make sure the dependencies are resolved correctly, and list changes here.

Does this PR add a new feature? If so, have you added samples on website?

  • [*] No. You can skip this section.
  • Yes. Make sure you have added samples following below steps.
  1. Find the corresponding markdown file for your new feature in website/docs/documentation folder.
    Make sure you choose the correct class estimators/transformers and namespace.
  2. Follow the pattern in markdown file and add another section for your new API, including pyspark, scala (and .NET potentially) samples.
  3. Make sure the DocTable points to correct API link.
  4. Navigate to website folder, and run yarn run start to make sure the website renders correctly.
  5. Don't forget to add <!--pytest-codeblocks:cont--> before each python code blocks to enable auto-tests for python samples.
  6. Make sure the WebsiteSamplesTests job pass in the pipeline.

…ng returned from reading a http response content. Which subsequently cause exception while parsing the json
@github-actions
Copy link

github-actions bot commented Aug 9, 2023

Hey @saileshbaidya 👋!
Thank you so much for contributing to our repository 🙌.
Someone from SynapseML Team will be reviewing this pull request soon.

We use semantic commit messages to streamline the release process.
Before your pull request can be merged, you should make sure your first commit and PR title start with a semantic prefix.
This helps us to create release messages and credit you for your hard work!

Examples of commit messages with semantic prefixes:

  • fix: Fix LightGBM crashes with empty partitions
  • feat: Make HTTP on Spark back-offs configurable
  • docs: Update Spark Serving usage
  • build: Add codecov support
  • perf: improve LightGBM memory usage
  • refactor: make python code generation rely on classes
  • style: Remove nulls from CNTKModel
  • test: Add test coverage for CNTKModel

To test your commit locally, please follow our guild on building from source.
Check out the developer guide for additional guidance on testing your change.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Summary by GPT-4

The code change adds a condition to check if the response content is empty before parsing it as JSON. If the content is empty, it returns an empty JsObject instead of attempting to parse the empty content. This prevents potential errors when trying to parse an empty response as JSON.

Suggestions

No suggestions are needed as the changes in this PR seem to be appropriate and well-implemented.

@saileshbaidya saileshbaidya changed the title This fixes a bug in our RestHelpers that would result into empty string returned from reading a http response content. Which subsequently cause exception while parsing the json fix: This fixes a bug in our RestHelpers that would result into empty string returned from reading a http response content. Which subsequently cause exception while parsing the json Aug 9, 2023
@saileshbaidya
Copy link
Contributor Author

Closing it. After discussing, it's better to emit exception so that client gets to decide what's an acceptable behavior for the rest apis.

@saileshbaidya saileshbaidya deleted the saibai/webUtilBugFix branch October 10, 2023 20:30
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.

2 participants