Skip to content

Commit

Permalink
removed HydraJobException (#1614)
Browse files Browse the repository at this point in the history
  • Loading branch information
omry authored May 11, 2021
1 parent 3f74e8f commit 8be4c62
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 23 deletions.
7 changes: 0 additions & 7 deletions hydra/_internal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from hydra.core.utils import get_valid_filename, validate_config_path
from hydra.errors import (
CompactHydraException,
HydraException,
InstantiationException,
SearchPathException,
)
Expand Down Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions hydra/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)


Expand Down Expand Up @@ -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:
Expand Down
6 changes: 0 additions & 6 deletions hydra/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

...
18 changes: 14 additions & 4 deletions tests/test_hydra.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 = [
Expand Down

0 comments on commit 8be4c62

Please sign in to comment.