From c41f152fa5b0bc44e15779e99706d7fb8431de85 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sun, 28 May 2023 13:02:48 +0200 Subject: Show PID in :process error message See https://www.reddit.com/r/qutebrowser/comments/13tqp55/command_crashed_see_process_for_details/ --- doc/changelog.asciidoc | 3 +++ qutebrowser/misc/guiprocess.py | 2 +- tests/unit/misc/test_guiprocess.py | 9 +++++---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/doc/changelog.asciidoc b/doc/changelog.asciidoc index 2beeceb4a..bbbf584cb 100644 --- a/doc/changelog.asciidoc +++ b/doc/changelog.asciidoc @@ -136,6 +136,9 @@ Changed - `:config-diff` now has an `--include-hidden` flag, which also shows internally-set settings. - Improved error messages when `:spawn` can't find an executable. +- When a process fails, the error message now suggests using `:process PID` with + the correct PID (rather than always showing the latest process, which might not + be the failing one) Fixed ~~~~~ diff --git a/qutebrowser/misc/guiprocess.py b/qutebrowser/misc/guiprocess.py index 3a6ab156a..00e8e210b 100644 --- a/qutebrowser/misc/guiprocess.py +++ b/qutebrowser/misc/guiprocess.py @@ -328,7 +328,7 @@ class GUIProcess(QObject): log.procs.error("Process stdout:\n" + self.stdout.strip()) if self.stderr: log.procs.error("Process stderr:\n" + self.stderr.strip()) - message.error(str(self.outcome) + " See :process for details.") + message.error(f"{self.outcome} See :process {self.pid} for details.") @pyqtSlot() def _on_started(self) -> None: diff --git a/tests/unit/misc/test_guiprocess.py b/tests/unit/misc/test_guiprocess.py index d225ab2e2..a272ff096 100644 --- a/tests/unit/misc/test_guiprocess.py +++ b/tests/unit/misc/test_guiprocess.py @@ -32,9 +32,10 @@ from qutebrowser.qt import sip @pytest.fixture -def proc(qtbot, caplog): +def proc(qtbot, caplog, monkeypatch): """A fixture providing a GUIProcess and cleaning it up after the test.""" p = guiprocess.GUIProcess('testprocess') + monkeypatch.setattr(p._proc, 'processId', lambda: 1234) yield p if not sip.isdeleted(p._proc) and p._proc.state() != QProcess.ProcessState.NotRunning: with caplog.at_level(logging.ERROR): @@ -429,7 +430,7 @@ def test_exit_unsuccessful(qtbot, proc, message_mock, py_proc, caplog): proc.start(*py_proc('import sys; sys.exit(1)')) msg = message_mock.getmsg(usertypes.MessageLevel.error) - expected = "Testprocess exited with status 1. See :process for details." + expected = "Testprocess exited with status 1. See :process 1234 for details." assert msg.text == expected assert not proc.outcome.running @@ -450,7 +451,7 @@ def test_exit_crash(qtbot, proc, message_mock, py_proc, caplog): """)) msg = message_mock.getmsg(usertypes.MessageLevel.error) - assert msg.text == "Testprocess crashed. See :process for details." + assert msg.text == "Testprocess crashed. See :process 1234 for details." assert not proc.outcome.running assert proc.outcome.status == QProcess.ExitStatus.CrashExit @@ -471,7 +472,7 @@ def test_exit_unsuccessful_output(qtbot, proc, caplog, py_proc, stream): """)) assert caplog.messages[-2] == 'Process {}:\ntest'.format(stream) assert caplog.messages[-1] == ( - 'Testprocess exited with status 1. See :process for details.') + 'Testprocess exited with status 1. See :process 1234 for details.') @pytest.mark.parametrize('stream', ['stdout', 'stderr']) -- cgit v1.2.3-54-g00ecf