diff --git a/news/not_found_repr.rst b/news/not_found_repr.rst new file mode 100644 index 000000000..a285e0fe1 --- /dev/null +++ b/news/not_found_repr.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**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:** + +* + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +* diff --git a/tests/procs/test_specs.py b/tests/procs/test_specs.py index cb29610e3..3ca4de536 100644 --- a/tests/procs/test_specs.py +++ b/tests/procs/test_specs.py @@ -201,7 +201,7 @@ def test_on_command_not_found_fires(xession): subproc = SubprocSpec.build(["xonshcommandnotfound"]) with pytest.raises(XonshError) as expected: subproc.run() - assert "command not found: xonshcommandnotfound" in str(expected.value) + assert "command not found: 'xonshcommandnotfound'" in str(expected.value) assert fired @@ -223,5 +223,5 @@ def test_on_command_not_found_doesnt_fire_in_non_interactive_mode(xession): subproc = SubprocSpec.build(["xonshcommandnotfound"]) with pytest.raises(XonshError) as expected: subproc.run() - assert "command not found: xonshcommandnotfound" in str(expected.value) + assert "command not found: 'xonshcommandnotfound'" in str(expected.value) assert not fired diff --git a/xonsh/procs/specs.py b/xonsh/procs/specs.py index 25fd83e67..c8bcf16ba 100644 --- a/xonsh/procs/specs.py +++ b/xonsh/procs/specs.py @@ -481,7 +481,7 @@ class SubprocSpec: return self.cls( ["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 sug = xt.suggest_commands(cmd0, env) if len(sug.strip()) > 0: