Skip to content

Commit

Permalink
Editor: Catch another error when opening a not available file
Browse files Browse the repository at this point in the history
This can happen on Windows for files on a network drive that is
not available when Spyder starts.
  • Loading branch information
ccordoba12 committed Apr 16, 2022
1 parent 48a9574 commit d8b9b02
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions spyder/plugins/editor/widgets/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1517,21 +1517,31 @@ def has_filename(self, filename):
# Try finding without calling the slow realpath
return data_filenames.index(filename)
except ValueError:
filename = fixpath(filename)
# See note about OSError on set_current_filename
# Fixes spyder-ide/spyder#17685
try:
filename = fixpath(filename)
except OSError:
return None

for index, editor_filename in enumerate(data_filenames):
if filename == fixpath(editor_filename):
return index
return None

def set_current_filename(self, filename, focus=True):
"""Set current filename and return the associated editor instance."""
# This is necessary to catch an error on Windows for files in a
# directory junction pointing to a symlink whose target is on a
# network drive that is unavailable at startup.
# FileNotFoundError: This is necessary to catch an error on Windows
# for files in a directory junction pointing to a symlink whose target
# is on a network drive that is unavailable at startup.
# Fixes spyder-ide/spyder#15714
# OSError: This is necessary to catch an error on Windows when Spyder
# was closed with a file in a shared folder on a different computer on
# the network, and is started again when that folder is not available.
# Fixes spyder-ide/spyder#17685
try:
index = self.has_filename(filename)
except FileNotFoundError:
except (FileNotFoundError, OSError):
index = None

if index is not None:
Expand Down

0 comments on commit d8b9b02

Please sign in to comment.