Using repr(cmd) for command not found (#5075)

repr cmd

Co-authored-by: a <1@1.1>
This commit is contained in:
Andy Kipp 2023-03-02 11:43:36 +06:00 committed by GitHub
parent 0c713a0c31
commit ec378090ce
Failed to generate hash of commit
3 changed files with 26 additions and 3 deletions

23
news/not_found_repr.rst Normal file
View file

@ -0,0 +1,23 @@
**Added:**
* <news item>
**Changed:**
* The `command not found` error will show the ``repr(cmd)`` to uncover the cases when the command name has ``\n``, ``\t`` or not visible color codes and raises the error.
**Deprecated:**
* <news item>
**Removed:**
* <news item>
**Fixed:**
* <news item>
**Security:**
* <news item>

View file

@ -201,7 +201,7 @@ def test_on_command_not_found_fires(xession):
subproc = SubprocSpec.build(["xonshcommandnotfound"]) subproc = SubprocSpec.build(["xonshcommandnotfound"])
with pytest.raises(XonshError) as expected: with pytest.raises(XonshError) as expected:
subproc.run() subproc.run()
assert "command not found: xonshcommandnotfound" in str(expected.value) assert "command not found: 'xonshcommandnotfound'" in str(expected.value)
assert fired assert fired
@ -223,5 +223,5 @@ def test_on_command_not_found_doesnt_fire_in_non_interactive_mode(xession):
subproc = SubprocSpec.build(["xonshcommandnotfound"]) subproc = SubprocSpec.build(["xonshcommandnotfound"])
with pytest.raises(XonshError) as expected: with pytest.raises(XonshError) as expected:
subproc.run() subproc.run()
assert "command not found: xonshcommandnotfound" in str(expected.value) assert "command not found: 'xonshcommandnotfound'" in str(expected.value)
assert not fired assert not fired

View file

@ -481,7 +481,7 @@ class SubprocSpec:
return self.cls( return self.cls(
["man", cmd0.rstrip("?")], bufsize=bufsize, **kwargs ["man", cmd0.rstrip("?")], bufsize=bufsize, **kwargs
) )
e = f"xonsh: subprocess mode: command not found: {cmd0}" e = f"xonsh: subprocess mode: command not found: {repr(cmd0)}"
env = XSH.env env = XSH.env
sug = xt.suggest_commands(cmd0, env) sug = xt.suggest_commands(cmd0, env)
if len(sug.strip()) > 0: if len(sug.strip()) > 0: