Skip to content

Commit

Permalink
Add handling of errors during VS Code extension installation
Browse files Browse the repository at this point in the history
Ref. eng/recordflux/RecordFlux!1490
  • Loading branch information
treiher committed Mar 22, 2024
1 parent 24f2781 commit 4fef4ab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion rflx/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,10 @@ def install(args: argparse.Namespace) -> None:

elif args.ide is IDE.VSCODE:
with importlib_resources.as_file(vscode_extension()) as extension:
subprocess.run(["code", "--install-extension", extension, "--force"], check=False)
try:
subprocess.run(["code", "--install-extension", extension, "--force"], check=True)
except (FileNotFoundError, subprocess.CalledProcessError) as e:
fail(f"installation of VS Code extension failed: {e}", Subsystem.CLI)

else:
assert_never(args.ide) # pragma: no cover
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,18 @@ def test_install_vscode_extension(monkeypatch: pytest.MonkeyPatch, tmp_path: Pat

assert run_called == [["code", "--install-extension", vscode_extension, "--force"]]

def run_mock(cmd: object, check: object) -> subprocess.CompletedProcess[object]: # noqa: ARG001
raise FileNotFoundError("file not found")

monkeypatch.setattr(subprocess, "run", run_mock)

assert (
str(
cli.main(["rflx", "install", "vscode"]),
)
== "cli: error: installation of VS Code extension failed: file not found"
)


def test_install_invalid() -> None:
args = ["rflx", "install", "invalid"]
Expand Down

0 comments on commit 4fef4ab

Please sign in to comment.