From ffda07051a22ed08ca78c4449e8ada59592f7e57 Mon Sep 17 00:00:00 2001 From: almaz Date: Tue, 18 Jun 2024 17:06:39 +0200 Subject: [PATCH] added exception handler --- agent/worker/task_logged.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/agent/worker/task_logged.py b/agent/worker/task_logged.py index abf122f..b5b42c5 100644 --- a/agent/worker/task_logged.py +++ b/agent/worker/task_logged.py @@ -125,15 +125,25 @@ def end_log_stop(self): return sly.EventType.TASK_STOPPED def end_log_crash(self, e): - exc_str = traceback.format_exc() + from supervisely.io.exception_handlers import handle_exception + + trace_str = traceback.format_exc() + + handled_exc = handle_exception(e) + if handled_exc is not None: + exit_status = handled_exc.title + exc_str = handled_exc.get_message_for_exception() + else: + exit_status = str(e) + exc_str = repr(e) self.logger.warn( "TASK_END", extra={ "event_type": sly.EventType.TASK_CRASHED, - "exit_status": str(e), - "exc_str": repr(e), - "trace": exc_str, + "exit_status": exit_status, + "exc_str": exc_str, + "trace": trace_str, }, ) return sly.EventType.TASK_CRASHED