From 3b8ed34b18020e45143ecee83fab46c37b574c33 Mon Sep 17 00:00:00 2001 From: gleize Date: Fri, 1 Mar 2024 10:32:02 -0800 Subject: [PATCH 1/2] Embed original traceback in Hydra's exception report. --- hydra/core/utils.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/hydra/core/utils.py b/hydra/core/utils.py index 43ff3649a76..0a8151cc431 100644 --- a/hydra/core/utils.py +++ b/hydra/core/utils.py @@ -186,7 +186,7 @@ def run_job( ret.return_value = task_function(task_cfg) ret.status = JobStatus.COMPLETED except Exception as e: - ret.return_value = e + ret.return_value = traceback.TracebackException(*sys.exc_info()) ret.status = JobStatus.FAILED ret.task_name = JobRuntime.instance().get("name") @@ -237,6 +237,14 @@ class JobStatus(Enum): COMPLETED = 1 FAILED = 2 +class JobException(Exception): + def __init__(self, traceback_exception: traceback.TracebackException) -> None: + super().__init__() + self.traceback_exception = traceback_exception + + def __str__(self) -> str: + body = "".join(self.traceback_exception.format()) + return f"JobException(\n{body})\n" @dataclass class JobReturn: @@ -257,7 +265,7 @@ def return_value(self) -> Any: sys.stderr.write( f"Error executing job with overrides: {self.overrides}" + os.linesep ) - raise self._return_value + raise JobException(self._return_value) @return_value.setter def return_value(self, value: Any) -> None: From 78f00766b5f37672aa7232ebbf01bdd74246bd60 Mon Sep 17 00:00:00 2001 From: gleize Date: Fri, 12 Apr 2024 15:23:19 -0700 Subject: [PATCH 2/2] Add missing import. --- hydra/core/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/hydra/core/utils.py b/hydra/core/utils.py index 0a8151cc431..738cff699ad 100644 --- a/hydra/core/utils.py +++ b/hydra/core/utils.py @@ -12,6 +12,7 @@ from pathlib import Path from textwrap import dedent from typing import Any, Dict, Optional, Sequence, Union, cast +import traceback from omegaconf import DictConfig, OmegaConf, open_dict, read_write