How to catch Sublime Text exceptions on their Python interpreter? -
how catch sublime text exceptions on python interpreter?
this migrated https://github.com/sublimetextissues/core/issues/1359
i trying catch exception:
try: print( 'running' ) sublime.active_window().run_command( "side_bar_update_sync" ) isnotsyncedsidebarenabled = false print( 'running this' ) except baseexception: isnotsyncedsidebarenabled = true print( 'running also' )
but when ran, not catches it. not matter if try within typeerror
, exception
or baseexception
classes. below full exception output.
reloading plugin sublimedefaultsyntax.default_syntax read_pref_async!!!! updateissyncedsidebarenabled!!!! running traceback (most recent call last): file "d:\user\dropbox\applications\softwareversioning\sublimetext\sublime_plugin.py", line 538, in run_ return self.run() typeerror: run() missing 1 required positional argument: 'enable' running isnotsyncedsidebarenabled: false
the problem is, python cannot catch exception throwed run_command( "side_bar_update_sync" )
. exception catching errors trying call self.view
, when there no self passed by, working fine. full code:
def plugin_loaded(): global isnotsyncedsidebarenabled packagecontrolsettings = sublime.load_settings('package control.sublime-settings') usersettings = sublime.load_settings('preferences.sublime-settings') def updateissyncedsidebarenabled(): global isnotsyncedsidebarenabled print(' updateissyncedsidebarenabled!!!!') sublime.active_window().run_command( "reveal_in_side_bar" ) try: print( 'running' ) sublime.active_window().run_command( "side_bar_update_sync" ) isnotsyncedsidebarenabled = false print( 'running this' ) except baseexception: isnotsyncedsidebarenabled = true print( 'running also' ) print( 'isnotsyncedsidebarenabled: ' + str( isnotsyncedsidebarenabled ) ) def read_pref_async(): print('read_pref_async!!!!') updateissyncedsidebarenabled() def read_pref_package(): print('read_pref_package!!!!') updateissyncedsidebarenabled() def read_pref_preferences(): print('read_pref_preferences!!!!') updateissyncedsidebarenabled() # read initial setting, after packages being loaded sublime.set_timeout_async( read_pref_async, 1000 ) # listen changes packagecontrolsettings.add_on_change( "package control", read_pref_package ) usersettings.add_on_change( "preferences", read_pref_preferences ) #print( usersettings.get( "ignored_packages" ) ) #print( packagecontrolsettings.get( "installed_packages" ) )
this discussion may followed sublime text forum's thread: https://forum.sublimetext.com/t/how-to-add-remove-a-default-menu-entry-when-a-x-package-is-isnt-enabled-installed/22753?u=addons_zz
this lines file showed on exception:
532 class applicationcommand(command): 533 def run_(self, edit_token, args): 534 args = self.filter_args(args) 535 if args: 536 return self.run(**args) 537 else: 538 return self.run() 539 540 def run(self): 541 pass1 542 543 ... other classes
as stated on question, indeed bug on sublime text. here's smaller repro bug report:
import sublime_plugin class testcommandcommand(sublime_plugin.textcommand): def run(self, edit): try: ret = self.view.window().run_command("toggle_comment", {"fuck": "no"}) except: print("an exception") else: print(ret)
console:
reloading plugin user.test command: test_command traceback (most recent call last): file "c:\program files\sublime text 3\sublime_plugin.py", line 792, in run_ return self.run(edit, **args) typeerror: run() got unexpected keyword argument 'fuck' none
needless say, happens python commands , not internal commands since not error @ all. when try run command sublime.active_window().run_command( "reveal_in_side_bar" )
, not exist, sublime text not throw exception. allow plugins or menu entries not throw errors when not available.
Comments
Post a Comment