From caab415defbcf2ab266bb7fefd18e24246073f7f Mon Sep 17 00:00:00 2001 From: Meder Kamalov <38204337+mederka@users.noreply.github.com> Date: Tue, 31 Jan 2023 19:38:20 +0100 Subject: [PATCH] chore: show EnvironmentCreationError content (#75) * chore: show EnvironmentCreationError content * Stringify causing env creation errors * Fix tests --- src/isolate/backends/conda.py | 8 ++++---- src/isolate/backends/virtualenv.py | 6 +++--- src/isolate/server/server.py | 7 ++----- tests/test_server.py | 4 ++-- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/isolate/backends/conda.py b/src/isolate/backends/conda.py index 8456bc6..39edfc2 100644 --- a/src/isolate/backends/conda.py +++ b/src/isolate/backends/conda.py @@ -117,8 +117,8 @@ def create(self, *, force: bool = False) -> Path: ) except subprocess.SubprocessError as exc: raise EnvironmentCreationError( - "Failure during 'conda create'" - ) from exc + f"Failure during 'conda create': {exc}" + ) else: # Since our agent needs Python to be installed (at very least) @@ -140,8 +140,8 @@ def create(self, *, force: bool = False) -> Path: ) except subprocess.SubprocessError as exc: raise EnvironmentCreationError( - "Failure during 'conda create'" - ) from exc + f"Failure during 'conda create': {exc}" + ) self.log(f"New environment cached at '{env_path}'") return env_path diff --git a/src/isolate/backends/virtualenv.py b/src/isolate/backends/virtualenv.py index cd427dd..deeae5e 100644 --- a/src/isolate/backends/virtualenv.py +++ b/src/isolate/backends/virtualenv.py @@ -84,7 +84,7 @@ def install_requirements(self, path: Path) -> None: stderr=stderr, ) except subprocess.SubprocessError as exc: - raise EnvironmentCreationError("Failure during 'pip install'.") from exc + raise EnvironmentCreationError(f"Failure during 'pip install': {exc}") def _install_python_through_pyenv(self) -> str: from isolate.backends.pyenv import PyenvEnvironment @@ -137,8 +137,8 @@ def create(self, *, force: bool = False) -> Path: cli_run(args) except (RuntimeError, OSError) as exc: raise EnvironmentCreationError( - f"Failed to create the environment at '{venv_path}'" - ) from exc + f"Failed to create the environment at '{venv_path}': {exc}" + ) self.install_requirements(venv_path) diff --git a/src/isolate/server/server.py b/src/isolate/server/server.py index 8e6441d..4782d9f 100644 --- a/src/isolate/server/server.py +++ b/src/isolate/server/server.py @@ -173,11 +173,8 @@ def Run( # the future is completed, the timeout here should be redundant # but it is just in case. environment_paths.append(future.result(timeout=0.1)) - except EnvironmentCreationError: - return self.abort_with_msg( - f"A problem occurred while creating the environment.", - context, - ) + except EnvironmentCreationError as e: + return self.abort_with_msg(f"{e}", context) primary_path, *inheritance_paths = environment_paths inheritance_paths.extend(extra_inheritance_paths) diff --git a/tests/test_server.py b/tests/test_server.py index 684bef9..021df63 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -183,7 +183,7 @@ def test_server_builder_error(stub: definitions.IsolateStub, monkeypatch: Any) - with pytest.raises(grpc.RpcError) as exc: run_request(stub, request, build_logs=build_logs) - assert exc.match("A problem occurred while creating the environment") + assert "Failure during 'pip install': Command" in exc.value.details() raw_logs = [log.message for log in build_logs] assert "ERROR: Invalid requirement: '$$$$'" in raw_logs @@ -358,7 +358,7 @@ def test_agent_show_logs_from_agent_requirements( with pytest.raises(grpc.RpcError) as exc: run_request(stub, request, build_logs=build_logs) - assert exc.match("A problem occurred while creating the environment") + assert "Failure during 'pip install': Command" in exc.value.details() raw_logs = [log.message for log in build_logs] assert "ERROR: Invalid requirement: '$$$$'" in raw_logs