mirror of
https://github.com/gradio-app/gradio.git
synced 2025-04-06 12:30:29 +08:00
Document gr.Error (#3465)
* add docstrings and document error * fix link in guide * changelog * lint
This commit is contained in:
parent
226e87cd54
commit
302982c71e
@ -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:
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user