Skip to content

Commit

Permalink
Clarify error message when executed binary not found
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanv committed Sep 23, 2024
1 parent fe4fcc9 commit 612adde
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
7 changes: 4 additions & 3 deletions spin/cmds/meson.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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:
Expand Down
8 changes: 6 additions & 2 deletions spin/cmds/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
10 changes: 10 additions & 0 deletions spin/tests/test_util.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 612adde

Please sign in to comment.