summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2021-03-15 20:23:24 +0100
committerFlorian Bruhin <me@the-compiler.org>2021-03-15 20:23:24 +0100
commit0b621cb0ce2b54d3f93d8d41d8ff4257888a87e5 (patch)
tree1811ce597e588b9c9868d65a44fde3172bd640e7
parentdf2b817aa418ea7a83c5cbe523aab58ef26a2b20 (diff)
downloadqutebrowser-0b621cb0ce2b54d3f93d8d41d8ff4257888a87e5.tar.gz
qutebrowser-0b621cb0ce2b54d3f93d8d41d8ff4257888a87e5.zip
Improve error messages for GUIProcess
-rw-r--r--qutebrowser/misc/guiprocess.py23
-rw-r--r--tests/end2end/features/spawn.feature2
-rw-r--r--tests/unit/misc/test_guiprocess.py7
3 files changed, 28 insertions, 4 deletions
diff --git a/qutebrowser/misc/guiprocess.py b/qutebrowser/misc/guiprocess.py
index 79c84c346..4aa3df55d 100644
--- a/qutebrowser/misc/guiprocess.py
+++ b/qutebrowser/misc/guiprocess.py
@@ -84,8 +84,27 @@ class GUIProcess(QObject):
if error == QProcess.Crashed and not utils.is_windows:
# Already handled via ExitStatus in _on_finished
return
- msg = self._proc.errorString()
- message.error("Error while spawning {}: {}".format(self._what, msg))
+
+ what = f"{self._what} {self.cmd!r}"
+ error_descriptions = {
+ QProcess.FailedToStart: f"{what.capitalize()} failed to start",
+ QProcess.Crashed: f"{what.capitalize()} crashed",
+ QProcess.Timedout: f"{what.capitalize()} timed out",
+ QProcess.WriteError: f"Write error for {what}",
+ QProcess.WriteError: f"Read error for {what}",
+ }
+ error_string = self._proc.errorString()
+ msg = ': '.join([error_descriptions[error], error_string])
+
+ # We can't get some kind of error code from Qt...
+ # https://bugreports.qt.io/browse/QTBUG-44769
+ # However, it looks like those strings aren't actually translated?
+ known_errors = ['No such file or directory', 'Permission denied']
+ if (': ' in error_string and
+ error_string.split(': ', maxsplit=1)[1] in known_errors):
+ msg += f'\n(Hint: Make sure {self.cmd!r} exists and is executable)'
+
+ message.error(msg)
@pyqtSlot(int, QProcess.ExitStatus)
def _on_finished(self, code, status):
diff --git a/tests/end2end/features/spawn.feature b/tests/end2end/features/spawn.feature
index 11b344439..1c360893c 100644
--- a/tests/end2end/features/spawn.feature
+++ b/tests/end2end/features/spawn.feature
@@ -8,7 +8,7 @@ Feature: :spawn
Scenario: Running :spawn with command that does not exist
When I run :spawn command_does_not_exist127623
- Then the error "Error while spawning command: *" should be shown
+ Then the error "Command 'command_does_not_exist127623' failed to start: *" should be shown
Scenario: Starting a userscript which doesn't exist
When I run :spawn -u this_does_not_exist
diff --git a/tests/unit/misc/test_guiprocess.py b/tests/unit/misc/test_guiprocess.py
index 9e1b3916c..18e926fab 100644
--- a/tests/unit/misc/test_guiprocess.py
+++ b/tests/unit/misc/test_guiprocess.py
@@ -226,7 +226,12 @@ def test_error(qtbot, proc, caplog, message_mock):
proc.start('this_does_not_exist_either', [])
msg = message_mock.getmsg(usertypes.MessageLevel.error)
- assert msg.text.startswith("Error while spawning testprocess:")
+ assert msg.text.startswith(
+ "Testprocess 'this_does_not_exist_either' failed to start:")
+
+ if not utils.is_windows:
+ assert msg.text.endswith(
+ "(Hint: Make sure 'this_does_not_exist_either' exists and is executable)")
def test_exit_unsuccessful(qtbot, proc, message_mock, py_proc, caplog):