Document gr.Error (#3465)

* add docstrings and document error

* fix link in guide

* changelog

* lint
This commit is contained in:
Ali Abdalla 2023-03-14 20:00:26 -07:00 committed by GitHub
parent 226e87cd54
commit 302982c71e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 2 deletions

View File

@ -11,7 +11,7 @@ Fixed issue with `gr.Request` object failing to handle dictionaries when nested
## Documentation Changes:
No changes to highlight.
- Document gr.Error in the docs by [@aliabd](https://github.com/aliabd) in [PR 3465](https://github.com/gradio-app/gradio/pull/3465)
## Testing and Infrastructure Changes:

View File

@ -1,3 +1,8 @@
from gradio.documentation import document, set_documentation_group
set_documentation_group("helpers")
class DuplicateBlockError(ValueError):
"""Raised when a Blocks contains more than one Block with the same id"""
@ -14,8 +19,19 @@ class InvalidApiName(ValueError):
pass
@document()
class Error(Exception):
"""
This class allows you to pass custom error messages to the user. You can do so by raising a gr.Error("custom message") anywhere in the code, and when that line is executed the custom message will appear in a modal on the demo.
Demos: calculator
"""
def __init__(self, message: str):
"""
Parameters:
message: The error message to be displayed to the user.
"""
self.message = message
super().__init__(self.message)

View File

@ -26,7 +26,7 @@ Continue learning about examples in the [More On Examples](https://gradio.app/mo
## Errors
You wish to pass custom error messages to the user. To do so, raise a `gr.Error("custom message")` to display an error message. If you try to divide by zero in the calculator demo above, a popup modal will display the custom error message. Learn more about Error in the [docs](https://gradio.app/docs#errors).
You wish to pass custom error messages to the user. To do so, raise a `gr.Error("custom message")` to display an error message. If you try to divide by zero in the calculator demo above, a popup modal will display the custom error message. Learn more about Error in the [docs](https://gradio.app/docs#error).
## Descriptive Content