Skip to content

switch_between_code_and_test crashes on untitled views: AttributeError on file_name().split #2

Description

@dpc00

Package Control: CodeTestSwitcher 2014.09.12.14.06.52 (python 3.3) on Sublime Text 4200 / Windows.

Repro. Open an unsaved scratch (no file_name()), then run switch_between_code_and_test.

Result. Uncaught exception; nothing happens in the buffer.

Traceback (most recent call last):
  File ".../python33/sublime_plugin.py", line 1437, in run_
    return self.run(edit)
  File ".../CodeTestSwitcher.sublime-package/code_test_switcher.py", line 10, in run
  File ".../CodeTestSwitcher.sublime-package/code_test_switcher.py", line 23, in opposite_file_names
AttributeError: 'NoneType' object has no attribute 'split'

Cause. opposite_file_names does:

file_name = self.view.file_name().split(os.sep)[-1]

view.file_name() is None for untitled buffers.

Fix. Return early (or show the existing "No file found" message) when there is no path:

def opposite_file_names(self):
    path = self.view.file_name()
    if not path:
        return []
    file_name = path.split(os.sep)[-1]
    ...

Did not run the project-walk path (os.walk of every window folder) on a saved file.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions