From 612adde79a28809dd7ebbdf21d29fb2066e5288e Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Mon, 23 Sep 2024 09:37:39 -0700 Subject: [PATCH] Clarify error message when executed binary not found Closes #236 --- spin/cmds/meson.py | 7 ++++--- spin/cmds/util.py | 8 ++++++-- spin/tests/test_util.py | 10 ++++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 spin/tests/test_util.py diff --git a/spin/cmds/meson.py b/spin/cmds/meson.py index f49e6fd..a4a0c63 100644 --- a/spin/cmds/meson.py +++ b/spin/cmds/meson.py @@ -480,8 +480,9 @@ def test( package = cfg.get("tool.spin.package", None) if package is None: - print( - "Please specify `package = packagename` under `tool.spin` section of `pyproject.toml`" + click.secho( + "Please specify `package = packagename` under `tool.spin` section of `pyproject.toml`", + fg="bright_red", ) raise SystemExit(1) @@ -503,7 +504,7 @@ def test( "Error: cannot generate coverage report for editable installs", fg="bright_red", ) - raise SystemExit(-1) + raise SystemExit(1) build_cmd = _get_configured_command("build") if build_cmd: diff --git a/spin/cmds/util.py b/spin/cmds/util.py index 2a840d3..bf2f9d4 100644 --- a/spin/cmds/util.py +++ b/spin/cmds/util.py @@ -67,12 +67,16 @@ def run( print(f"Failed to launch `{cmd}`") sys.exit(-1) else: - p = subprocess.run(cmd, *args, **kwargs) + try: + p = subprocess.run(cmd, *args, **kwargs) + except FileNotFoundError: + click.secho(f"`{cmd[0]}` executable not found. Exiting.", fg="bright_red") + raise SystemExit(1) from None if p.returncode != 0 and sys_exit: # Output was suppressed, but the process failed, so print it anyway if output is False: print(p.stdout.decode("utf-8"), end="") - sys.exit(p.returncode) + raise SystemExit(p.returncode) return p diff --git a/spin/tests/test_util.py b/spin/tests/test_util.py new file mode 100644 index 0000000..3aa2b18 --- /dev/null +++ b/spin/tests/test_util.py @@ -0,0 +1,10 @@ +import pytest + +from spin.cmds import util + + +def test_cmd_not_found(capsys): + with pytest.raises(SystemExit): + util.run(["gdb1", "-e", "script"]) + output = capsys.readouterr() + assert "executable not found" in output.out