gradio-app / gradio

Build and share delightful machine learning apps, all in Python. 🌟 Star to support our work!
http://www.gradio.app
Apache License 2.0
30.37k stars 2.26k forks source link

Make exceptions in the Client more specific #8264

Closed abidlabs closed 1 month ago

abidlabs commented 1 month ago

Previously, If an exception was raised in the upstream app due to an invalid value provided by the Python Client, then the error that is raised is not very informative:

ValueError: None

My initial thought was to transmit the error from the server to the client to provide better error messages. However, we intentionally do not reveal exceptions to users of Gradio applications as they can reveal security vulnerabilities, unless show_error=True.

So this PR only prints the upstream exception if show_error=True, otherwise prints a generic error explaining how to print more detailed errors. For other types of errors that the Client can generate, e.g. when an invalid parameter is provided, it changes the errors to be TypeError instead of ValueError -- that's consistent with the error type that is raised when you call a function in Python with the wrong parameters.

Closes: https://github.com/gradio-app/gradio/issues/7889

gradio-pr-bot commented 1 month ago

🪼 branch checks and previews

• Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
:unicorn: Changes detecting...

Install Gradio from this PR

pip install https://gradio-builds.s3.amazonaws.com/8d91c14aa50754fca4fceb1f8f9582923a3523f0/gradio-4.31.0-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@8d91c14aa50754fca4fceb1f8f9582923a3523f0#subdirectory=client/python"
gradio-pr-bot commented 1 month ago

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
gradio patch
gradio_client patch

With the following changelog entry.

Make exceptions in the Client more specific

Maintainers or the PR author can modify the PR title to modify this entry.

#### Something isn't right? - Maintainers can change the version label to modify the version bump. - If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can [update the changelog file directly](https://github.com/gradio-app/gradio/edit/specific-exceptions/.changeset/blue-frogs-fetch.md).
abidlabs commented 1 month ago

Thanks @freddyaboulton for the review!