From a13306a79fe9ce3521e93bbce29ffb534e7a498a Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sun, 21 Sep 2025 18:29:54 +0200 Subject: [PATCH] Fix exception when quitting with download prompt open If we have a pending download with a prompt and quit qutebrowser, we get: mainwindow:closeEvent:715 Closing window 0 quitter:shutdown:221 Shutting down with status 0, session None... prompt:shutdown:121 Shutting down with loops [] quitter:shutdown:235 Deferring shutdown stage 2 prompt:ask_question:179 Ending loop.exec() for option=None text='Please enter a location for https://proof.ovh.net/files/1Mb.dat' title='Save file to:'> prompt:ask_question:181 Restoring old question None prompt:_on_show_prompts:299 Deleting old prompt qutebrowser.mainwindow.prompt.DownloadFilenamePrompt(question= option=None text='Please enter a location for https://proof.ovh.net/files/1Mb.dat' title='Save file to:'>) prompt:_on_show_prompts:303 No prompts left, hiding prompt container. objreg:on_destroyed:112 schedule removal: 0 objreg:on_destroyed:112 schedule removal: tab [...] objreg:on_destroyed:112 schedule removal: 0 objreg:on_destroyed:112 schedule removal: main-window objreg:on_destroyed:112 schedule removal: tabbed-browser objreg:on_destroyed:112 schedule removal: status-command objreg:on_destroyed:112 schedule removal: completion objreg:on_destroyed:112 schedule removal: mode-manager objreg:on_destroyed:112 schedule removal: hintmanager objreg:on_destroyed:112 schedule removal: prompt-container quitter:_shutdown_2:241 Stage 2 of shutting down... [...] webenginedownloads:_on_state_changed:63 State for changed to DownloadCancelled downloads:_on_begin_remove_row:1076 _on_begin_remove_row with idx 0, webengine True downloads:_remove_item:995 Removed download 1: 1Mb.dat [100%|?.??B] modeman:leave:429 Leaving mode KeyMode.prompt (reason: aborted) crashsignal:_handle_early_exits:229 Uncaught exception Traceback (most recent call last): File "[...]/qutebrowser/mainwindow/prompt.py", line 344, in _on_aborted modeman.leave(self._win_id, key_mode, 'aborted', maybe=True) ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "[...]/qutebrowser/keyinput/modeman.py", line 214, in leave instance(win_id).leave(mode, reason, maybe=maybe) ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "[...]/qutebrowser/keyinput/modeman.py", line 435, in leave self.left.emit(mode, self.mode, self._win_id) ^^^^^^^^^ RuntimeError: wrapped C/C++ object of type ModeManager has been deleted --- qutebrowser/mainwindow/prompt.py | 4 ++-- tests/end2end/features/downloads.feature | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/qutebrowser/mainwindow/prompt.py b/qutebrowser/mainwindow/prompt.py index 3f618a279..c8045c0e8 100644 --- a/qutebrowser/mainwindow/prompt.py +++ b/qutebrowser/mainwindow/prompt.py @@ -342,9 +342,9 @@ class PromptContainer(QWidget): """Leave KEY_MODE whenever a prompt is aborted.""" try: modeman.leave(self._win_id, key_mode, 'aborted', maybe=True) - except objreg.RegistryUnavailableError: + except (objreg.RegistryUnavailableError, RuntimeError): # window was deleted: ignore - pass + log.prompt.debug(f"Ignoring leaving {key_mode} as window was deleted") @pyqtSlot(usertypes.KeyMode) def _on_prompt_done(self, key_mode): diff --git a/tests/end2end/features/downloads.feature b/tests/end2end/features/downloads.feature index df04625a8..369befa99 100644 --- a/tests/end2end/features/downloads.feature +++ b/tests/end2end/features/downloads.feature @@ -129,6 +129,14 @@ Feature: Downloading things from a website. And I wait for "Download drip finished" in the log Then the downloaded file drip should be 128 bytes big + Scenario: Shutting down with a download question + When I set downloads.location.prompt to true + And I open data/downloads/download.bin without waiting + And I wait for "Asking question option=None text='Please enter a location for http://localhost:*/data/downloads/download.bin' title='Save file to:'>, *" in the log + And I run :close + Then qutebrowser should quit + # (and no crash should happen) + Scenario: Downloading a file with spaces When I open data/downloads/download with spaces.bin without waiting And I wait until the download is finished