SublimeText / PackageDev

Tools to ease the creation of snippets, syntax definitions, etc. for Sublime Text.
MIT License
435 stars 82 forks source link

AttributeError: 'bool' object has no attribute 'endswith' #154

Closed evandrocoan closed 7 years ago

evandrocoan commented 7 years ago

I just opened Sublime Text, and changed the Sublime Project ruler: (perhaps this is unrelated to this problem)

![](https://user-images.githubusercontent.com/5332158/30840830-e82a7cd6-a24f-11e7-8e18-e780090ab1b0.gif)


I looked into the console and found this: ``` Traceback (most recent call last): File "D:\SublimeText\sublime_plugin.py", line 280, in lambda: check_view_event_listeners(view)) File "D:\SublimeText\sublime_plugin.py", line 267, in check_view_event_listeners want = is_view_event_listener_applicable(cls, view) File "D:\SublimeText\sublime_plugin.py", line 232, in is_view_event_listener_applicable if not cls.is_applicable(view.settings()): File "D:\SublimeText\Data\Packages\PackageDev\plugins_\settings\__init__.py", line 86, in is_applicable return (syntax.endswith("/Sublime Text Settings.sublime-syntax") AttributeError: 'bool' object has no attribute 'endswith' ``` Full log:

``` DPI scale: 1 startup, version: 3144 windows x32 channel: dev executable: /D/SublimeText/sublime_text.exe working dir: /C/ProgramData/Microsoft/Windows/Start Menu/Atalhos packages path: /D/SublimeText/Data/Packages state path: /D/SublimeText/Data/Local zip path: /D/SublimeText/Packages zip path: /D/SublimeText/Data/Installed Packages ignored_packages: ["All Autocomplete", "Anaconda", "ApplySyntax", "BracketHighlighter", "C++ Completions", "C++ Snippets", "C++ Starting Kit", "ColorHelper", "DictionaryAutoComplete", "FileManager", "Find++", "FuzzyFilePath", "Gist", "Git", "GitGutter", "GotoLastEditEnhanced", "Javatar", "Jedi - Python autocompletion", "Local History", "Matlab Completions", "MatlabFilenameAutoComplete", "MySQL Snippets", "Project Specific Syntax Settings", "Qt Completions for C++", "ScopeAlways", "sublime-text-2-buildview", "SublimeCodeIntel", "SyncedSideBar", "TypeScript", "Vintage", "WordHighlight"] Unable to parse binding {keys: [ctrl+alt+w]} Unable to parse binding {keys: [ctrl+shift+w]} Errors parsing theme: icon_file_type is missing layer0.opacity, setting to 1.0 for backwards compatibility pre session restore time: 2.28461 loading dictionary Packages/User/MultiLingual Dictionary/EN_PT.dic startup time: 5.35761 first paint time: 5.38961 reloading plugin Default.auto_indent_tag reloading plugin Default.block reloading plugin Default.comment reloading plugin Default.convert_syntax reloading plugin Default.copy_path reloading plugin Default.delete_word reloading plugin Default.detect_indentation reloading plugin Default.duplicate_line reloading plugin Default.echo reloading plugin Default.exec reloading plugin Default.fold reloading plugin Default.font reloading plugin Default.goto_line reloading plugin Default.history_list reloading plugin Default.indentation reloading plugin Default.install_package_control reloading plugin Default.kill_ring reloading plugin Default.mark reloading plugin Default.new_templates reloading plugin Default.open_context_url reloading plugin Default.open_in_browser reloading plugin Default.pane reloading plugin Default.paragraph reloading plugin Default.paste_from_history reloading plugin Default.profile reloading plugin Default.quick_panel reloading plugin Default.run_syntax_tests reloading plugin Default.save_on_focus_lost reloading plugin Default.scroll reloading plugin Default.set_unsaved_view_name reloading plugin Default.settings reloading plugin Default.show_scope_name reloading plugin Default.side_bar reloading plugin Default.sort reloading plugin Default.swap_line reloading plugin Default.switch_file reloading plugin Default.symbol reloading plugin Default.transform reloading plugin Default.transpose reloading plugin Default.trim_trailing_white_space reloading plugin Default.ui reloading plugin CSS.css_completions reloading plugin Diff.diff reloading plugin HTML.encode_html_entities reloading plugin HTML.html_completions reloading plugin 0_package_control_loader.00-package_control reloading plugin 0_package_control_loader.01-package_setting_context reloading plugin 0_package_control_loader.01-pygments reloading plugin 0_package_control_loader.15-coverage reloading plugin 0_package_control_loader.50-backrefs reloading plugin 0_package_control_loader.50-markupsafe reloading plugin 0_package_control_loader.50-python-markdown reloading plugin 0_package_control_loader.50-pyyaml reloading plugin 0_package_control_loader.50-regex reloading plugin 0_package_control_loader.51-python-jinja2 reloading plugin 0_package_control_loader.55-mdpopups reloading plugin A File Icon.A File Icon reloading plugin Active View Jump Back.active_view_jump_back reloading plugin Add Folder To Project.AddFolderToProject reloading plugin Advanced CSV.csvplugin === NumPy disabled, using TinyNumPy instead === To enable cell evaluation using the full NumPy, download NumPy from: https://pypi.python.org/pypi/numpy and install it into Sublime Text's Packages directory. For information on the features and limitations of TinyNumPy, visit: https://github.com/wadetb/tinynumpy ====================== reloading plugin AdvancedNewFile.AdvancedNewFile reloading plugin Alignment.Alignment reloading plugin AlignTab.aligner reloading plugin AlignTab.aligntab reloading plugin AlignTab.hist reloading plugin AlignTab.parser reloading plugin AlignTab.table reloading plugin AlignTab.wclen reloading plugin amxmodx.AMXXEditor reloading plugin ANSIescape.ansi reloading plugin Auto Refresh.AutoRefresh reloading plugin AutoFileName.autofilename reloading plugin AutoFileName.getimageinfo reloading plugin AutomaticPackageReloader.package_reloader reloading plugin AutoWrap.autowrap reloading plugin Better CoffeeScript.CoffeeScript reloading plugin BetterFindBuffer.find_results reloading plugin BufferScroll.BufferScroll reloading plugin Case Conversion.case_conversion reloading plugin Case Conversion.case_parse reloading plugin Case Conversion.ToggleTitleCase reloading plugin Chain of Command.chain reloading plugin ChangeQuotes.change_quotes reloading plugin ChannelRepositoryTools.ordereddict reloading plugin ChannelRepositoryTools.tests reloading plugin ChannelRepositoryTools.upgrade reloading plugin Clear Cursors Carets.clear_cursors_carets reloading plugin Clickable URLs.clickable_urls reloading plugin Clipboard Scope Copy.clipboard_scope_copy reloading plugin Color Highlighter.ColorHighlighter reloading plugin Color Highlighter.colors reloading plugin ColorSchemeEditor.ColorSchemeEditor-ST2 reloading plugin Column Select.column_select reloading plugin Compare Side-By-Side.sbs_compare reloading plugin ConvertToUTF8.ConvertToUTF8 reloading plugin Copy Filepath With Line Numbers.CopyFilepathWithLineNumbers reloading plugin CopyWithLineNumbersReloaded.copy_with_line_numbers reloading plugin Default Syntax.default_syntax reloading plugin Delete Current File.DeleteCurrentFile reloading plugin DistractionFreeWindow.distraction_free_window reloading plugin DocBlockr.jsdocs reloading plugin DocBlockr.test_runner reloading plugin DuplicateSelections.duplicate_selections reloading plugin Edit Preferences.__init__ reloading plugin Edit Preferences.commands_base reloading plugin Edit Preferences.edit_package_files reloading plugin Edit Preferences.extract_snippets reloading plugin Edit Preferences.helper_commands reloading plugin Edit Preferences.helpers reloading plugin Edit Preferences.insert_binding_repr reloading plugin Edit Preferences.jsonix reloading plugin Edit Preferences.list_commands reloading plugin Edit Preferences.list_menu_bindings reloading plugin Edit Preferences.list_settings reloading plugin Edit Preferences.list_shortcut_keys reloading plugin Edit Preferences.list_theme_selectors reloading plugin Edit Preferences.package_resources reloading plugin Edit Preferences.quick_panel_cols reloading plugin Edit Preferences.scheduler reloading plugin Emmet.emmet-plugin reloading plugin ExportHtml.ExportBbcode reloading plugin ExportHtml.ExportHtml reloading plugin ExportHtml.HtmlAnnotations reloading plugin ExportHtml.support reloading plugin ExtendedTabSwitcher.ExtendedSwitcher reloading plugin Extract Text to File.extract_to_file reloading plugin File History.file_history reloading plugin File Rename.file_rename reloading plugin FileDiffs.file_diffs reloading plugin FindKeyConflicts.find_key_conflicts reloading plugin Fix Project Switch Restart Bug.fix_project_switch_restart_bug reloading plugin Fix Selection After Indent.fix_selection_after_indent reloading plugin Fixed Selections Clear.fixed_clear_selections reloading plugin Force Rewrite Sublime Settings.force_rewrite_sublime_settings reloading plugin FuzzyFileNav.fuzzy_file_nav reloading plugin FuzzyFileNav.multiconf reloading plugin FuzzyFileNav.notify reloading plugin Glue.__init__ reloading plugin Glue.Glue reloading plugin Glue.GlueBrowser reloading plugin Glue.GlueCmds reloading plugin Glue.GlueIO reloading plugin Glue.GlueSidebarOpener reloading plugin Google Spell Check.google-spell-check reloading plugin Highlight Build Errors.HighlightBuildErrors reloading plugin HighlightWords.HighlightWords reloading plugin Horizontal Scroll.scroll_width reloading plugin Hungry Backspace.hungry_backspace reloading plugin Increment Selection.IncrementSelection reloading plugin Incrementor.incrementor reloading plugin Indent and braces.indent-and-braces reloading plugin Indent Size.IndentSizeCommand reloading plugin Insert Nums.InsertNums reloading plugin Invert Selection.invertselection reloading plugin LaTeX Word Count.WordCount reloading plugin LaTeXSmartQuotes.getTeXRoot reloading plugin LaTeXSmartQuotes.smartquotes reloading plugin LaTeXTools.01_reload_submodules reloading plugin LaTeXTools.02_temp_file_cleanup reloading plugin LaTeXTools.03_reset_phantoms reloading plugin LaTeXTools.auto_label reloading plugin LaTeXTools.biblatex_crossref_completions reloading plugin LaTeXTools.biblatex_field_name_completions reloading plugin LaTeXTools.biblatex_name_completions reloading plugin LaTeXTools.biblatex_snippet_completions reloading plugin LaTeXTools.biblatex_syntax_listener reloading plugin LaTeXTools.change_environment reloading plugin LaTeXTools.context_provider reloading plugin LaTeXTools.create_mousemap reloading plugin LaTeXTools.delete_temp_files reloading plugin LaTeXTools.detect_spellcheck reloading plugin LaTeXTools.getTeXRoot reloading plugin LaTeXTools.jumpto_anywhere reloading plugin LaTeXTools.jumpto_tex_file reloading plugin LaTeXTools.jumpToPDF reloading plugin LaTeXTools.kpsewhich reloading plugin LaTeXTools.latex_cite_completions reloading plugin LaTeXTools.latex_cwl_completions reloading plugin LaTeXTools.latex_directive_completions reloading plugin LaTeXTools.latex_env_completions reloading plugin LaTeXTools.latex_fill_all reloading plugin LaTeXTools.latex_glossary_completions reloading plugin LaTeXTools.latex_input_completions reloading plugin LaTeXTools.latex_installed_packages reloading plugin LaTeXTools.latex_own_command_completions reloading plugin LaTeXTools.latex_ref_completions reloading plugin LaTeXTools.latexCommand reloading plugin LaTeXTools.latexDocumentationViewer reloading plugin LaTeXTools.latexEnvCloser reloading plugin LaTeXTools.latexEnvironment reloading plugin LaTeXTools.latextools_cache_listener reloading plugin LaTeXTools.latextools_default_settings reloading plugin LaTeXTools.latextools_plugin reloading plugin LaTeXTools.makePDF reloading plugin LaTeXTools.migrate reloading plugin LaTeXTools.open_detexify reloading plugin LaTeXTools.parseTeXlog reloading plugin LaTeXTools.reveal_folders reloading plugin LaTeXTools.search_commands reloading plugin LaTeXTools.smart_paste reloading plugin LaTeXTools.system_check reloading plugin LaTeXTools.texcount reloading plugin LaTeXTools.texMacro reloading plugin LaTeXTools.texSections reloading plugin LaTeXTools.texSyntaxListener reloading plugin LaTeXTools.toc_quickpanel reloading plugin LaTeXTools.toggle_settings reloading plugin LESS.less_completions reloading plugin Line Endings Unify.LineEndingsUnify reloading plugin Markdown Preview.helper reloading plugin Markdown Preview.markdown_settings reloading plugin Markdown Preview.markdown_wrapper reloading plugin Markdown Preview.MarkdownPreview reloading plugin Markdown to BB Code Converter.MarkdownToBBCode reloading plugin Maven.config_generator reloading plugin Maven.import reloading plugin Maven.maven reloading plugin MaxPane.layouts_doc reloading plugin MaxPane.max_pane reloading plugin MoveText.move_text reloading plugin MultiEditUtils.MultiEditUtils reloading plugin MultiEditUtils.selection_fields reloading plugin Number King.king reloading plugin Open Auto Completion.open_auto_completion reloading plugin Origami.origami reloading plugin Override Unpacked Packages.override_unpacked_packages reloading plugin OverrideAudit.override_audit reloading plugin OverrideAudit.settings_proxy reloading plugin Overwrite Commit Completion.overwrite_commit_completion reloading plugin Package Control.1_reloader reloading plugin Package Control.2_bootstrap reloading plugin Package Control.Package Control reloading plugin package_setting_context.__init__ reloading plugin PackageDev._logging reloading plugin PackageDev.main reloading plugin PackageResourceViewer.package_resource_viewer reloading plugin PackageResourceViewer.package_resources reloading plugin Path Translator.PathTranslator reloading plugin PowerCursors.power_cursors reloading plugin Pretty JSON.PrettyJson reloading plugin Pretty JSON.PrettyJsonListeners reloading plugin PythonDebugTools.debug_tools reloading plugin QuickSettings.QuickSettigns reloading plugin Random Everything.__init__ reloading plugin Random Everything.random reloading plugin REG.jumptoregkey reloading plugin ReIndent.ReIndent reloading plugin ScopeHunter.scope_hunter reloading plugin ScopeHunter.scope_hunter_notify reloading plugin ScopeHunter.support reloading plugin Select All Spelling Errors.select_all_spelling_errors reloading plugin SelectUntil.edit reloading plugin SelectUntil.select-until reloading plugin Side-by-Side Settings.sxs_settings reloading plugin SideBarEnhancements.SideBar reloading plugin SideBarEnhancements.SideBarAPI reloading plugin SideBarEnhancements.SideBarDefaultDisable reloading plugin SQL Keyword Uppercase.sql_keyword_uppercase reloading plugin SQLExec.SQLExec reloading plugin SQLTools.SQLTools reloading plugin StickySearch.StickySearch reloading plugin StudioChannel.sublime_text_studio reloading plugin StudioChannel.synced_side_bar_watcher reloading plugin StudioChannel.update reloading plugin Sublime Tutor.sublime_tutor reloading plugin SublimeLinter.commands reloading plugin SublimeLinter.sublimelinter reloading plugin SublimeLinter-javac.linter SublimeLinter: javac linter loaded reloading plugin SublimeREPL.__init__ reloading plugin SublimeREPL.completions reloading plugin SublimeREPL.lang_integration reloading plugin SublimeREPL.run_existing_command reloading plugin SublimeREPL.sublimerepl reloading plugin SublimeREPL.sublimerepl_build_system_hack reloading plugin SublimeREPL.text_transfer reloading plugin Sync View Scroll.syncscroll reloading plugin SyntaxManager.syntaxmgr reloading plugin TabsExtra.support reloading plugin TabsExtra.tab_menu reloading plugin TabsExtra.tab_sort_helper reloading plugin TabsExtra.tabs_extra reloading plugin Terminal.Terminal reloading plugin Text Pastry.text_pastry reloading plugin Text Pastry.text_pastry_addons reloading plugin Text Pastry.text_pastry_clipboard reloading plugin Text Pastry.text_pastry_selection reloading plugin Toggle Words.ToggleWords reloading plugin Trimmer.Trimmer reloading plugin UnitTesting.ut reloading plugin View Settings Freely.view_settings_freely reloading plugin Whitespace.Whitespace reloading plugin Wrap Plus.wrap_lines_enhancement reloading plugin Wrap Plus.wrap_plus plugins loaded Loaded LaTeXTools plugins ['traditional_bibliography', 'new_bibliography'] from path D:\SublimeText\Data\Packages\LaTeXTools\bibliography_plugins SublimeLinter: debug mode: on SublimeLinter: temp directory: c:\users\profes~1\appdata\local\temp\SublimeLinter3-Professional OverrideAudit: Sublime version is unchanged; skipping automatic report Loaded LaTeXTools plugins ['base_viewer'] from path D:\SublimeText\Data\Packages\LaTeXTools\viewers\base_viewer.py Loaded LaTeXTools plugins ['command_viewer', 'preview_viewer', 'okular_viewer', 'skim_viewer', 'zathura_viewer', 'evince_viewer', 'sumatra_viewer'] from path D:\SublimeText\Data\Packages\LaTeXTools\viewers syncScroll starting Loading LaTeXTools plugins... Emmet: No need to update PyV8 Loaded LaTeXTools plugins ['pdf_builder'] from path D:\SublimeText\Data\Packages\LaTeXTools\builders\pdfBuilder.py Loaded LaTeXTools plugins ['script_builder', 'simple_builder', 'basic_builder', 'traditional_builder'] from path D:\SublimeText\Data\Packages\LaTeXTools\builders Loaded LaTeXTools plugins [] from path D:\SublimeText\Data\Packages\LaTeXTools\bibliography_plugins Loaded LaTeXTools plugins [] from path D:\SublimeText\Data\Packages\LaTeXTools\viewers\base_viewer.py Loaded LaTeXTools plugins [] from path D:\SublimeText\Data\Packages\LaTeXTools\viewers Package Control: No updated packages Traceback (most recent call last): File "D:\SublimeText\sublime_plugin.py", line 280, in lambda: check_view_event_listeners(view)) File "D:\SublimeText\sublime_plugin.py", line 267, in check_view_event_listeners want = is_view_event_listener_applicable(cls, view) File "D:\SublimeText\sublime_plugin.py", line 232, in is_view_event_listener_applicable if not cls.is_applicable(view.settings()): File "D:\SublimeText\Data\Packages\PackageDev\plugins_\settings\__init__.py", line 86, in is_applicable return (syntax.endswith("/Sublime Text Settings.sublime-syntax") AttributeError: 'bool' object has no attribute 'endswith' indexing [job 3]: no files were indexed out of the 9 queued, abandoning crawl rule scope:source.regexp-replacement#escaped has a scope name, but is unreachable, so the name will never be used rule scope:source.regexp-replacement#escaped has a scope name, but is unreachable, so the name will never be used ```


The lines are: ```python File: PackageDev/plugins_/settings/__init__.py 82: @classmethod 83: def is_applicable(cls, settings): 84: """Enable the listener for Sublime Settings syntax only.""" 85: syntax = settings.get('syntax') or "" 86: return (syntax.endswith("/Sublime Text Settings.sublime-syntax") 87: or syntax.endswith("/Sublime Text Project.sublime-syntax")) 88: ``` Looking at it, I think the problem is `syntax = settings.get('syntax') or ""`. Would not this be explicitly a boolean? If the default value is supposed to be `""`, then it should be `settings.get('syntax', "")`.
r-stein commented 7 years ago

If you use an or it will use the second value if the first is falsity (False, None, empty array). Hence this will either be the first value or "" if the first value is a falsity. This has a very similar behavior as your suggestion, but additionally captures cases where the syntax is explicitly set to null. What is the output if you open the ST console and write view.settings().get("syntax")?

deathaxe commented 7 years ago

@r-stein is right, settings.get('syntax') or "" just avoids to create an empty string object for the default value argument, which is rarely used only.

Your issue can only be triggered by settings.get('syntax') returning True, which is indeed a quite odd situation.

evandrocoan commented 7 years ago

What is the output if you open the ST console and write view.settings().get("syntax")?

I got the correct value:

>>> view.settings().get("syntax")
'Packages/LaTeX/LaTeX.sublime-syntax'

So somehow the syntax was of some view was set to ?, for some time, which triggered the issue.

FichteFoll commented 7 years ago

This circumstance is so specific that basically no plugin I know would ever consider this. For example, no plugin dev would consider the syntax setting to contain an integer for example, and I'm instead just going to point to "somewhere else"* instead of attempting to validify that all standard settings adhere to their standard type restrictions.

If these were non-standard settings introduced by my package, I'd be more likely to check their type in case the wrong type causes a panic escalation of some sort, but this will almost always be an after thought based on a report with things going wrong rather than the default.

Thanks for the report regardless.

* implying user error or another third-party package interfering

evandrocoan commented 7 years ago

Thanks for looking into it. You correct, my if something is changing my syntax value to some unknown value, this something else should be fixed not all packages relying on the syntax setting value. Perhaps its is some other package or the core doing something it should not. I am going to look if I can figure out steps to precisely reproduce this issue.