diff --git a/hydra/_internal/utils.py b/hydra/_internal/utils.py index 72c5f65e169..139a35d7959 100644 --- a/hydra/_internal/utils.py +++ b/hydra/_internal/utils.py @@ -17,7 +17,6 @@ from hydra.core.utils import get_valid_filename, validate_config_path from hydra.errors import ( CompactHydraException, - HydraException, InstantiationException, SearchPathException, ) @@ -224,12 +223,6 @@ def run_and_report(func: Any) -> Any: # It is possible to add additional libraries to sanitize from the bottom later, # maybe even make it configurable. - # If got a HydraException that is caused by another exception, - # print the message of the HydraException and unwrap the cause. - if isinstance(ex, HydraException) and ex.__cause__ is not None: - sys.stderr.write(str(ex) + os.linesep) - ex = ex.__cause__ # type: ignore - tb: Any = ex.__traceback__ search_max = 10 # strip Hydra frames from start of stack diff --git a/hydra/core/utils.py b/hydra/core/utils.py index d5e208bf0a5..9b556a09aff 100644 --- a/hydra/core/utils.py +++ b/hydra/core/utils.py @@ -18,13 +18,11 @@ from hydra.core.hydra_config import HydraConfig from hydra.core.singleton import Singleton -from hydra.errors import HydraJobException +from hydra.types import HydraContext, TaskFunction if TYPE_CHECKING: from hydra._internal.callbacks import Callbacks -from hydra.types import HydraContext, TaskFunction - log = logging.getLogger(__name__) @@ -229,9 +227,10 @@ def return_value(self) -> Any: if self.status == JobStatus.COMPLETED: return self._return_value else: - raise HydraJobException( - f"Error executing job with overrides: {self.overrides}" - ) from self._return_value + sys.stderr.write( + f"Error executing job with overrides: {self.overrides}" + os.linesep + ) + raise self._return_value @return_value.setter def return_value(self, value: Any) -> None: diff --git a/hydra/errors.py b/hydra/errors.py index 1eb1a8c207a..a4dae765d50 100644 --- a/hydra/errors.py +++ b/hydra/errors.py @@ -39,9 +39,3 @@ def __init__( super(MissingConfigException, self).__init__(message) self.missing_cfg_file = missing_cfg_file self.options = options - - -class HydraJobException(HydraException): - """Raised when accessing a result of a failed job.""" - - ... diff --git a/tests/test_hydra.py b/tests/test_hydra.py index e6a19d88ace..574304c4065 100644 --- a/tests/test_hydra.py +++ b/tests/test_hydra.py @@ -1193,13 +1193,13 @@ def test_2(self) -> None: ), ], ) -def test_hydra_exception( - monkeypatch: Any, +def test_job_exception( tmpdir: Any, expected: str, ) -> None: - monkeypatch.chdir("tests/test_apps/app_exception") - ret = run_with_error(["my_app.py", f"hydra.run.dir={tmpdir}"]) + ret = run_with_error( + ["tests/test_apps/app_exception/my_app.py", f"hydra.run.dir={tmpdir}"] + ) assert_regex_match( from_line=expected, to_line=ret, @@ -1208,6 +1208,16 @@ def test_hydra_exception( ) +def test_job_exception_full_error(tmpdir: Any) -> None: + ret = run_with_error( + ["tests/test_apps/app_exception/my_app.py", f"hydra.run.dir={tmpdir}"], + env={**os.environ, "HYDRA_FULL_ERROR": "1"}, + ) + + assert "ZeroDivisionError: division by zero" in ret + assert "Set the environment variable HYDRA_FULL_ERROR=1" not in ret + + def test_structured_with_none_list(monkeypatch: Any, tmpdir: Path) -> None: monkeypatch.chdir("tests/test_apps/structured_with_none_list") cmd = [