spyder-ide / spyder

Official repository for Spyder - The Scientific Python Development Environment
https://www.spyder-ide.org
MIT License
8.25k stars 1.6k forks source link

Exception raised and strange behavior if all open files are deleted/moved outside Spyder #8814

Open CAM-Gerlach opened 5 years ago

CAM-Gerlach commented 5 years ago

Problem Description

If all the files I have open in Spyder are re/moved externally, I get odd behavior and an inconsistent/"desynced" split panel state on hitting "yes" to close the last file that leads to any number of exceptions, most commonly the one below. Specifically, after removing the files in the OS and switching back to Spyder, I get a "This file is available" warning for each file (as expected), but the last file open will only close in the active pane, not others, leaving the panes desynchronized. If I then click on that pane to make it active, I get the warning again for the same (last) file, and upon closing that one, I get the below error, presumably caused by Spyder trying to find the name of the file in the other pane in order to close it, and not finding it (likely, I'd run into others no matter what I did at that point due to the desync).

I can repro this following the below procedure with or without clean prefs, and once this occurs once (by the aforementioned method detailed below), keyboard shortcuts stop working in the Editor (even simple stuff like Ctrl-O) and thereafter closing any last file even by normal means will leave the active pane blank and the file open in any other panes, creating the same situation as above. Meanwhile, if I have a single panel open and repeat the procedure, everything closes without an error but no stock Untitled0 file is opened in the Editor like is always supposed to be the case (and is so when closing files normally if this error had first not been triggered), so calling any command at this point that expected an open file to act upon results in another exception.

So, we could catch this particular exception but much better to prevent the pane desync/blanking in the first place; I assume we could do so by examining the code in the function that triggers the close of the files when they are unavailable externally?

What steps reproduce the problem?

  1. Split the editor pane at least once
  2. Create two files (in Spyder or your OS)
  3. Ensure they are the only two files open in Spyder
  4. Delete/move them in your OS file manager
  5. Switch back to Spyder and click "Yes" (close) at each "File unavailable" warning

Alternatively,

  1. Have only one pane open
  2. Follow steps 2 through 5 above
  3. Trigger any command/menu item that requires a file to act upon (e.g. Change line endings)

Paste Traceback/Error Below (if applicable)

  File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\plugin.py", line 1222, in close_file_in_all_editorstacks
    index = editorstack.get_index_from_filename(filename)
  File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\editor.py", line 1453, in get_index_from_filename
    return filenames.index(filename)
ValueError: 'B:\\dev\\Bitzer\\glML\\temp3.py' is not in list

Versions

Dependencies

pygments >=2.0    :  2.3.1 (OK)
qdarkstyle >=2.6.4:  2.6.5 (OK)
sphinx >=0.6.6    :  1.8.4 (OK)
pyls >=0.19.0     :  0.21.5 (OK)
nbconvert >=4.0   :  5.4.0 (OK)
pandas >=0.13.1   :  0.24.1 (OK)
numpy >=1.7       :  1.15.4 (OK)
sympy >=0.7.3     :  1.3 (OK)
cython >=0.21     :  0.29.4 (OK)
qtconsole >=4.2.0 :  4.4.3 (OK)
IPython >=4.0     :  7.2.0 (OK)
matplotlib >=2.0.0:  3.0.2 (OK)
pylint >=0.25     :  2.2.2 (OK)
ccordoba12 commented 5 years ago

I can't reproduce this problem. Please create a video so I can see exactly what steps you're following to generate the error.

ccordoba12 commented 5 years ago

Sorry, this can be easily reproduced on Windows.