mirror of
https://github.com/gradio-app/gradio.git
synced 2025-03-07 11:46:51 +08:00
make printing the error message from a gr.Error
to the console configurable (#10158)
* make print_exc error configurable * add changeset * tweak * tweak * review: update traceback printing in queuing and utils --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com> Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
This commit is contained in:
parent
2b5530274a
commit
19e1ef52dc
5
.changeset/rotten-drinks-push.md
Normal file
5
.changeset/rotten-drinks-push.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"gradio": minor
|
||||
---
|
||||
|
||||
feat:make printing the error message from a `gr.Error` to the console configurable
|
@ -81,6 +81,7 @@ class Error(Exception):
|
||||
duration: float | None = 10,
|
||||
visible: bool = True,
|
||||
title: str = "Error",
|
||||
print_exception: bool = True,
|
||||
):
|
||||
"""
|
||||
Parameters:
|
||||
@ -88,11 +89,13 @@ class Error(Exception):
|
||||
duration: The duration in seconds to display the error message. If None or 0, the error message will be displayed until the user closes it.
|
||||
visible: Whether the error message should be displayed in the UI.
|
||||
title: The title to be displayed to the user at the top of the error modal.
|
||||
print_exception: Whether to print traceback of the error to the console when the error is raised.
|
||||
"""
|
||||
self.title = title
|
||||
self.message = message
|
||||
self.duration = duration
|
||||
self.visible = visible
|
||||
self.print_exception = print_exception
|
||||
super().__init__(self.message)
|
||||
|
||||
def __str__(self):
|
||||
|
@ -17,6 +17,7 @@ from gradio import route_utils, routes
|
||||
from gradio.data_classes import (
|
||||
PredictBodyInternal,
|
||||
)
|
||||
from gradio.exceptions import Error
|
||||
from gradio.helpers import TrackedIterable
|
||||
from gradio.route_utils import API_PREFIX
|
||||
from gradio.server_messages import (
|
||||
@ -637,7 +638,8 @@ class Queue:
|
||||
response["is_generating"] = not event.is_finished
|
||||
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
if not isinstance(e, Error) or e.print_exception:
|
||||
traceback.print_exc()
|
||||
response = None
|
||||
err = e
|
||||
for event in awake_events:
|
||||
@ -722,7 +724,8 @@ class Queue:
|
||||
if event.streaming:
|
||||
response["is_generating"] = not event.is_finished
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
if not isinstance(e, Error) or e.print_exception:
|
||||
traceback.print_exc()
|
||||
response = None
|
||||
err = e
|
||||
|
||||
@ -764,7 +767,8 @@ class Queue:
|
||||
for event in events:
|
||||
self.event_analytics[event._id]["process_time"] = duration
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
if not isinstance(e, Error) or e.print_exception:
|
||||
traceback.print_exc()
|
||||
finally:
|
||||
event_queue = self.event_queue_per_concurrency_id[events[0].concurrency_id]
|
||||
event_queue.current_concurrency -= 1
|
||||
|
@ -76,7 +76,7 @@ from gradio.data_classes import (
|
||||
SimplePredictBody,
|
||||
UserProvidedPath,
|
||||
)
|
||||
from gradio.exceptions import InvalidPathError
|
||||
from gradio.exceptions import Error, InvalidPathError
|
||||
from gradio.node_server import (
|
||||
start_node_server,
|
||||
)
|
||||
@ -998,7 +998,8 @@ class App(FastAPI):
|
||||
)
|
||||
except BaseException as error:
|
||||
content = utils.error_payload(error, app.get_blocks().show_error)
|
||||
traceback.print_exc()
|
||||
if not isinstance(error, Error) or error.print_exception:
|
||||
traceback.print_exc()
|
||||
return JSONResponse(
|
||||
content=content,
|
||||
status_code=500,
|
||||
|
@ -312,11 +312,12 @@ def watchfn(reloader: SourceFileReloader):
|
||||
str(reloader.demo_file)
|
||||
)
|
||||
exec(changed_demo_file, module.__dict__)
|
||||
except Exception:
|
||||
except Exception as error:
|
||||
print(
|
||||
f"Reloading {reloader.watch_module_name} failed with the following exception: "
|
||||
)
|
||||
traceback.print_exc()
|
||||
if not isinstance(error, Error) or error.print_exception:
|
||||
traceback.print_exc()
|
||||
mtimes = {}
|
||||
reloader.alert_change("error")
|
||||
reloader.app.reload_error_message = traceback.format_exc()
|
||||
|
Loading…
Reference in New Issue
Block a user