Skip to content

Commit

Permalink
chore: show EnvironmentCreationError content (#75)
Browse files Browse the repository at this point in the history
* chore: show EnvironmentCreationError content

* Stringify causing env creation errors

* Fix tests
  • Loading branch information
mederka authored Jan 31, 2023
1 parent 293a42c commit caab415
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/isolate/backends/conda.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/isolate/backends/virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
7 changes: 2 additions & 5 deletions src/isolate/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit caab415

Please sign in to comment.