From 46512b4a51083973d0bc7a0ee5aad1e4319b3b8b Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Fri, 2 Sep 2022 11:39:00 -0500 Subject: [PATCH] Editor: Catch error when removing autosave files --- spyder/plugins/editor/utils/autosave.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/spyder/plugins/editor/utils/autosave.py b/spyder/plugins/editor/utils/autosave.py index ec41c4824d9..6edf8c9482f 100644 --- a/spyder/plugins/editor/utils/autosave.py +++ b/spyder/plugins/editor/utils/autosave.py @@ -315,7 +315,15 @@ def remove_autosave_file(self, filename): msgbox = AutosaveErrorDialog(action, error) msgbox.exec_if_enabled() del self.name_mapping[filename] - del self.file_hashes[autosave_filename] + + # This is necessary to catch an error when a file is changed externally + # but it's left unsaved in Spyder. + # Fixes spyder-ide/spyder#19283 + try: + del self.file_hashes[autosave_filename] + except KeyError: + pass + self.save_autosave_mapping() logger.debug('Removing autosave file %s', autosave_filename)