Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embed original traceback in Hydra's exception report. #2863

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions hydra/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -186,7 +187,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")
Expand Down Expand Up @@ -237,6 +238,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:
Expand All @@ -257,7 +266,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:
Expand Down
Loading