diff --git a/src/octoprint/cli/plugins.py b/src/octoprint/cli/plugins.py index facfc80cb..c1a7938f9 100644 --- a/src/octoprint/cli/plugins.py +++ b/src/octoprint/cli/plugins.py @@ -92,7 +92,8 @@ class OctoPrintPluginCommands(click.MultiCommand): continue result[name + self.sep + command.name] = command except: - self._logger.exception("Error while retrieving cli commands for plugin {}".format(name)) + self._logger.exception("Error while retrieving cli commands for plugin {}".format(name), + extra=dict(plugin=name)) return result diff --git a/src/octoprint/environment.py b/src/octoprint/environment.py index 6b22a22ac..86e673121 100644 --- a/src/octoprint/environment.py +++ b/src/octoprint/environment.py @@ -125,7 +125,8 @@ class EnvironmentDetector(object): result[implementation._identifier] = additional except: self._logger.exception("Error while fetching additional " - "environment data from plugin {}".format(implementation._identifier)) + "environment data from plugin {}".format(implementation._identifier), + extra=dict(plugin=implementation._identifier)) return result diff --git a/src/octoprint/events.py b/src/octoprint/events.py index a5fe562ba..74374f7ec 100644 --- a/src/octoprint/events.py +++ b/src/octoprint/events.py @@ -186,8 +186,7 @@ class EventManager(object): octoprint.plugin.call_plugin(octoprint.plugin.types.EventHandlerPlugin, "on_event", - args=(event, payload), - initialized=True) + args=(event, payload)) self._logger.info("Event loop shut down") except: self._logger.exception("Ooops, the event bus worker loop crashed") diff --git a/src/octoprint/filemanager/__init__.py b/src/octoprint/filemanager/__init__.py index 8521e814e..8124c06ce 100644 --- a/src/octoprint/filemanager/__init__.py +++ b/src/octoprint/filemanager/__init__.py @@ -78,7 +78,9 @@ def full_extension_tree(): continue result = octoprint.util.dict_merge(result, plugin_result, leaf_merger=leaf_merger) except: - logging.getLogger(__name__).exception("Exception while retrieving additional extension tree entries from SlicerPlugin {name}".format(name=plugin.key)) + logging.getLogger(__name__).exception("Exception while retrieving additional extension " + "tree entries from SlicerPlugin {name}".format(name=plugin._identifier), + extra=dict(plugin=plugin._identifier)) extension_tree_hooks = octoprint.plugin.plugin_manager().get_hooks("octoprint.filemanager.extension_tree") for name, hook in extension_tree_hooks.items(): @@ -88,7 +90,9 @@ def full_extension_tree(): continue result = octoprint.util.dict_merge(result, hook_result, leaf_merger=leaf_merger) except: - logging.getLogger(__name__).exception("Exception while retrieving additional extension tree entries from hook {name}".format(name=name)) + logging.getLogger(__name__).exception("Exception while retrieving additional extension " + "tree entries from hook {name}".format(name=name), + extra=dict(plugin=name)) return result @@ -429,7 +433,8 @@ class FileManager(object): try: plugin.on_slicing_progress(slicer, source_location, source_path, dest_location, dest_path, progress) except: - self._logger.exception("Exception while sending slicing progress to plugin %s" % plugin._identifier) + self._logger.exception("Exception while sending slicing progress to plugin %s" % plugin._identifier, + extra=dict(plugin=plugin._identifier)) import threading thread = threading.Thread(target=call_plugins, args=(slicer, source_location, source_path, dest_location, dest_path, progress_int)) @@ -464,11 +469,11 @@ class FileManager(object): if printer_profile is None: printer_profile = self._printer_profile_manager.get_current_or_default() - for hook in self._preprocessor_hooks.values(): + for name, hook in self._preprocessor_hooks.items(): try: hook_file_object = hook(path, file_object, links=links, printer_profile=printer_profile, allow_overwrite=allow_overwrite) except: - self._logger.exception("Error when calling preprocessor hook {}, ignoring".format(hook)) + self._logger.exception("Error when calling preprocessor hook for plugin {}, ignoring".format(name), extra=dict(plugin=name)) continue if hook_file_object is not None: diff --git a/src/octoprint/plugin/__init__.py b/src/octoprint/plugin/__init__.py index fceee2de2..500e1090a 100644 --- a/src/octoprint/plugin/__init__.py +++ b/src/octoprint/plugin/__init__.py @@ -196,8 +196,7 @@ def call_plugin(types, method, args=None, kwargs=None, callback=None, error_call error_callback (function): A callback to invoke after the call of an implementation resulted in an exception. Will be called with the three arguments ``name``, ``plugin`` and ``exc``. ``name`` will be the plugin identifier, ``plugin`` the plugin implementation instance itself and ``exc`` the caught exception. - initialized (boolean): Whether the plugin needs to be initialized (True) or not (False). Initialization status - is determined be presence of injected ``_identifier`` property. + initialized (boolean): Ignored. """ if not isinstance(types, (list, tuple)): @@ -211,7 +210,7 @@ def call_plugin(types, method, args=None, kwargs=None, callback=None, error_call plugins = plugin_manager().get_implementations(*types, sorting_context=sorting_context) for plugin in plugins: - if initialized and not hasattr(plugin, "_identifier"): + if not hasattr(plugin, "_identifier"): continue if hasattr(plugin, method): @@ -221,7 +220,7 @@ def call_plugin(types, method, args=None, kwargs=None, callback=None, error_call if callback: callback(plugin._identifier, plugin, result) except Exception as exc: - logger.exception("Error while calling plugin %s" % plugin._identifier) + logger.exception("Error while calling plugin %s" % plugin._identifier, extra=dict(plugin=plugin._identifier)) if error_callback: error_callback(plugin._identifier, plugin, exc) diff --git a/src/octoprint/plugins/forcelogin/__init__.py b/src/octoprint/plugins/forcelogin/__init__.py index a9f510cca..03b0083ac 100644 --- a/src/octoprint/plugins/forcelogin/__init__.py +++ b/src/octoprint/plugins/forcelogin/__init__.py @@ -87,7 +87,8 @@ class ForceLoginPlugin(octoprint.plugin.UiPlugin, if isinstance(assets, (tuple, list)): additional_assets += assets except: - self._logger.exception("Error fetching theming CSS to include from plugin {}".format(name)) + self._logger.exception("Error fetching theming CSS to include from plugin {}".format(name), + extra=dict(plugin=name)) render_kwargs.update(dict(forcelogin_theming=additional_assets)) return make_response(render_template("forcelogin_index.jinja2", **render_kwargs)) diff --git a/src/octoprint/plugins/pluginmanager/__init__.py b/src/octoprint/plugins/pluginmanager/__init__.py index 8bdedc49a..5caa980b6 100644 --- a/src/octoprint/plugins/pluginmanager/__init__.py +++ b/src/octoprint/plugins/pluginmanager/__init__.py @@ -902,7 +902,8 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin, reconnect_hooks.extend(filter(lambda x: isinstance(x, basestring), result)) except: self._logger.exception("Error while retrieving additional hooks for which a " - "reconnect is required from plugin {name}".format(**locals())) + "reconnect is required from plugin {name}".format(**locals()), + extra=dict(plugin=name)) return reconnect_hooks diff --git a/src/octoprint/plugins/softwareupdate/__init__.py b/src/octoprint/plugins/softwareupdate/__init__.py index 289910127..199b8a965 100644 --- a/src/octoprint/plugins/softwareupdate/__init__.py +++ b/src/octoprint/plugins/softwareupdate/__init__.py @@ -119,7 +119,9 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, try: hook_checks = hook() except: - self._logger.exception("Error while retrieving update information from plugin {name}".format(**locals())) + self._logger.exception("Error while retrieving update information " + "from plugin {name}".format(**locals()), + extra=dict(plugin=name)) else: for key, default_config in hook_checks.items(): if key in effective_configs or key == "octoprint": diff --git a/src/octoprint/printer/standard.py b/src/octoprint/printer/standard.py index 7d2ebcdf8..5beac173e 100644 --- a/src/octoprint/printer/standard.py +++ b/src/octoprint/printer/standard.py @@ -95,7 +95,8 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): self._logger.info("Using print time estimator provided by {}".format(name)) self._estimator_factory = estimator except: - self._logger.exception("Error while processing analysis queues from {}".format(name)) + self._logger.exception("Error while processing analysis queues from {}".format(name), + extra=dict(plugin=name)) #hook card upload self.sd_card_upload_hooks = plugin_manager().get_hooks("octoprint.printer.sdcardupload") @@ -229,7 +230,8 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): try: plugin.on_print_progress(storage, filename, progress) except: - self._logger.exception("Exception while sending print progress to plugin %s" % plugin._identifier) + self._logger.exception("Exception while sending print progress to plugin %s" % plugin._identifier, + extra=dict(plugin=plugin._identifier)) thread = threading.Thread(target=call_plugins, args=(storage, filename, progress)) thread.daemon = False @@ -721,7 +723,9 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): if result is not None: return result except: - self._logger.exception("There was an error running the sd upload hook provided by plugin {}".format(name)) + self._logger.exception("There was an error running the sd upload " + "hook provided by plugin {}".format(name), + extra=dict(plugin=name)) else: # no plugin feels responsible, use the default implementation diff --git a/src/octoprint/server/__init__.py b/src/octoprint/server/__init__.py index 6b90ca4af..4899a94d5 100644 --- a/src/octoprint/server/__init__.py +++ b/src/octoprint/server/__init__.py @@ -288,7 +288,8 @@ class Server(object): additional_factories = hook() analysis_queue_factories.update(**additional_factories) except: - self._logger.exception("Error while processing analysis queues from {}".format(name)) + self._logger.exception("Error while processing analysis queues from {}".format(name), + extra=dict(plugin=name)) analysisQueue = octoprint.filemanager.analysis.AnalysisQueue(analysis_queue_factories) slicingManager = octoprint.slicing.SlicingManager(self._settings.getBaseFolder("slicingProfiles"), printerProfileManager) @@ -345,7 +346,8 @@ class Server(object): self._logger.debug("Created user manager instance from factory {}".format(name)) break except: - self._logger.exception("Error while creating user manager instance from factory {}".format(name)) + self._logger.exception("Error while creating user manager instance from factory {}".format(name), + extra=dict(plugin=name)) else: name = self._settings.get(["accessControl", "userManager"]) try: @@ -368,7 +370,8 @@ class Server(object): self._logger.debug("Created printer instance from factory {}".format(name)) break except: - self._logger.exception("Error while creating printer instance from factory {}".format(name)) + self._logger.exception("Error while creating printer instance from factory {}".format(name), + extra=dict(plugin=name)) else: printer = Printer(fileManager, analysisQueue, printerProfileManager) components.update(dict(printer=printer)) @@ -457,7 +460,8 @@ class Server(object): constant, value = octoprint.events.Events.register_event(event, prefix="plugin_{}_".format(name)) self._logger.debug("Registered event {} of plugin {} as Events.{} = \"{}\"".format(event, name, constant, value)) except: - self._logger.exception("Error while retrieving custom event list from plugin {}".format(name)) + self._logger.exception("Error while retrieving custom event list from plugin {}".format(name), + extra=dict(plugin=name)) pluginManager.implementation_inject_factories=[octoprint_plugin_inject_factory, settings_plugin_inject_factory] @@ -468,7 +472,9 @@ class Server(object): try: settings_plugin_config_migration_and_cleanup(implementation._identifier, implementation) except: - self._logger.exception("Error while trying to migrate settings for plugin {}, ignoring it".format(implementation._identifier)) + self._logger.exception("Error while trying to migrate settings for " + "plugin {}, ignoring it".format(implementation._identifier), + extra=dict(plugin=plugin._identifier)) pluginManager.implementation_post_inits=[settings_plugin_config_migration_and_cleanup] @@ -540,7 +546,8 @@ class Server(object): try: access_validators_from_plugins.append(util.tornado.access_validation_factory(app, hook)) except: - self._logger.exception("Error while adding tornado access validator from plugin {}".format(plugin)) + self._logger.exception("Error while adding tornado access validator from plugin {}".format(plugin), + extra=dict(plugin=plugin)) admin_validators = [util.tornado.access_validation_factory(app, util.flask.admin_validator),] + access_validators_from_plugins user_validators = [util.tornado.access_validation_factory(app, util.flask.user_validator),] + access_validators_from_plugins @@ -606,7 +613,9 @@ class Server(object): try: result = hook(list(server_routes)) except: - self._logger.exception("There was an error while retrieving additional server routes from plugin hook {name}".format(**locals())) + self._logger.exception("There was an error while retrieving additional " + "server routes from plugin hook {name}".format(**locals()), + extra=dict(plugin=name)) else: if isinstance(result, (list, tuple)): for entry in result: @@ -649,7 +658,9 @@ class Server(object): try: result = hook(list(max_body_sizes)) except: - self._logger.exception("There was an error while retrieving additional upload sizes from plugin hook {name}".format(**locals())) + self._logger.exception("There was an error while retrieving additional " + "upload sizes from plugin hook {name}".format(**locals()), + extra=dict(plugin=name)) else: if isinstance(result, (list, tuple)): for entry in result: @@ -1179,7 +1190,9 @@ class Server(object): blueprint, prefix = self._prepare_blueprint_plugin(plugin) blueprints[prefix] = blueprint except: - self._logger.exception("Error while registering blueprint of plugin {}, ignoring it".format(plugin._identifier)) + self._logger.exception("Error while registering blueprint of " + "plugin {}, ignoring it".format(plugin._identifier), + extra=dict(plugin=plugin._identifier)) continue return blueprints @@ -1195,7 +1208,9 @@ class Server(object): blueprint, prefix = self._prepare_asset_plugin(plugin) blueprints[prefix] = blueprint except: - self._logger.exception("Error while registering assets of plugin {}, ignoring it".format(plugin._identifier)) + self._logger.exception("Error while registering assets of plugin " + "{}, ignoring it".format(plugin._identifier), + extra=dict(plugin=plugin._identifier)) continue return blueprints @@ -1243,7 +1258,8 @@ class Server(object): for h in result: blueprint.before_request(h) except: - self._logger.exception("Error processing before_request hooks from plugin {}".format(name)) + self._logger.exception("Error processing before_request hooks from plugin {}".format(name), + extra=dict(plugin=name)) for name, hook in after_hooks.items(): try: @@ -1252,7 +1268,8 @@ class Server(object): for h in result: blueprint.after_request(h) except: - self._logger.exception("Error processing after_request hooks from plugin {}".format(name)) + self._logger.exception("Error processing after_request hooks from plugin {}".format(name), + extra=dict(plugin=name)) def _setup_assets(self): global app diff --git a/src/octoprint/server/api/__init__.py b/src/octoprint/server/api/__init__.py index e67529d8b..dbcdaa6ef 100644 --- a/src/octoprint/server/api/__init__.py +++ b/src/octoprint/server/api/__init__.py @@ -60,15 +60,20 @@ def pluginData(name): if len(api_plugins) > 1: return make_response("More than one api provider registered for {name}, can't proceed".format(name=name), 500) - api_plugin = api_plugins[0] - if api_plugin.is_api_adminonly() and not current_user.is_admin(): - return make_response("Forbidden", 403) + try: + api_plugin = api_plugins[0] + if api_plugin.is_api_adminonly() and not current_user.is_admin(): + return make_response("Forbidden", 403) - response = api_plugin.on_api_get(request) + response = api_plugin.on_api_get(request) - if response is not None: - return response - return NO_CONTENT + if response is not None: + return response + return NO_CONTENT + except Exception: + logging.getLogger(__name__).exception("Error calling SimpleApiPlugin {}".format(name), + extra=dict(plugin=name)) + return abort(500) #~~ commands for plugins @@ -84,21 +89,26 @@ def pluginCommand(name): return make_response("More than one api provider registered for {name}, can't proceed".format(name=name), 500) api_plugin = api_plugins[0] - valid_commands = api_plugin.get_api_commands() - if valid_commands is None: - return make_response("Method not allowed", 405) + try: + valid_commands = api_plugin.get_api_commands() + if valid_commands is None: + return make_response("Method not allowed", 405) - if api_plugin.is_api_adminonly() and not current_user.is_admin(): - return make_response("Forbidden", 403) + if api_plugin.is_api_adminonly() and not current_user.is_admin(): + return make_response("Forbidden", 403) - command, data, response = get_json_command_from_request(request, valid_commands) - if response is not None: - return response + command, data, response = get_json_command_from_request(request, valid_commands) + if response is not None: + return response - response = api_plugin.on_api_command(command, data) - if response is not None: - return response - return NO_CONTENT + response = api_plugin.on_api_command(command, data) + if response is not None: + return response + return NO_CONTENT + except Exception: + logging.getLogger(__name__).exception("Error while excuting SimpleApiPlugin {}".format(name), + extra=dict(plugin=name)) + return abort(500) #~~ first run setup @@ -119,7 +129,9 @@ def wizardState(): version = implementation.get_wizard_version() ignored = octoprint.plugin.WizardPlugin.is_wizard_ignored(seen_wizards, implementation) except: - logging.getLogger(__name__).exception("There was an error fetching wizard details for {}, ignoring".format(name)) + logging.getLogger(__name__).exception("There was an error fetching wizard " + "details for {}, ignoring".format(name), + extra=dict(plugin=name)) else: result[name] = dict(required=required, details=details, version=version, ignored=ignored) @@ -154,7 +166,9 @@ def wizardFinish(): if name in handled: seen_wizards[name] = implementation.get_wizard_version() except: - logging.getLogger(__name__).exception("There was an error finishing the wizard for {}, ignoring".format(name)) + logging.getLogger(__name__).exception("There was an error finishing the " + "wizard for {}, ignoring".format(name), + extra=dict(plugin=name)) s().set(["server", "seenWizards"], seen_wizards) s().save() diff --git a/src/octoprint/server/api/settings.py b/src/octoprint/server/api/settings.py index 70b73ef81..aba8bac41 100644 --- a/src/octoprint/server/api/settings.py +++ b/src/octoprint/server/api/settings.py @@ -276,7 +276,8 @@ def _get_plugin_settings(): logger.warn("octoprint.plugin.SettingsPlugin.on_settings_load(self) instead.") except: logger.exception("Could not load settings for plugin {name} ({version})".format(version=plugin._plugin_version, - name=plugin._plugin_name)) + name=plugin._plugin_name), + extra=dict(plugin=plugin._identifier)) return data @@ -551,6 +552,8 @@ def _saveSettings(data): logger.warn("Please contact the plugin's author and ask to update the plugin to use a direct call like") logger.warn("octoprint.plugin.SettingsPlugin.on_settings_save(self, data) instead.") except: - logger.exception("Could not save settings for plugin {name} ({version})".format(version=plugin._plugin_version, name=plugin._plugin_name)) + logger.exception("Could not save settings for plugin {name} ({version})".format(version=plugin._plugin_version, + name=plugin._plugin_name), + extra=dict(plugin=plugin._identifier)) s.save(trigger_event=True) diff --git a/src/octoprint/server/apps/__init__.py b/src/octoprint/server/apps/__init__.py index 6cbe20c72..04d8edf87 100644 --- a/src/octoprint/server/apps/__init__.py +++ b/src/octoprint/server/apps/__init__.py @@ -107,7 +107,9 @@ def _get_registered_apps(): logger.warn("Plugin {} is still implementing the appkey hook that is deprecated since 1.3.11 and will be removed in 1.4.0. Switch it over to the Application Keys Plugin workflow.".format(name)) except: import logging - logging.getLogger(__name__).exception("Error while retrieving additional appkeys from plugin {name}".format(**locals())) + logging.getLogger(__name__).exception("Error while retrieving additional appkeys " + "from plugin {name}".format(**locals()), + extra=dict(plugin=name)) continue any_version_enabled = dict() diff --git a/src/octoprint/server/util/__init__.py b/src/octoprint/server/util/__init__.py index 970a98731..e2cea3630 100644 --- a/src/octoprint/server/util/__init__.py +++ b/src/octoprint/server/util/__init__.py @@ -193,7 +193,9 @@ def get_user_for_apikey(apikey): if user is not None: return user except: - logging.getLogger(__name__).exception("Error running api key validator for plugin {} and key {}".format(name, apikey)) + logging.getLogger(__name__).exception("Error running api key validator " + "for plugin {} and key {}".format(name, apikey), + extra=dict(plugin=name)) return None diff --git a/src/octoprint/server/util/flask.py b/src/octoprint/server/util/flask.py index 593d7872e..62f8905bf 100644 --- a/src/octoprint/server/util/flask.py +++ b/src/octoprint/server/util/flask.py @@ -1539,7 +1539,8 @@ def collect_plugin_assets(enable_gcodeviewer=True, preferred_stylesheet="css"): all_assets = implementation.get_assets() basefolder = implementation.get_asset_folder() except: - logger.exception("Got an error while trying to collect assets from {}, ignoring assets from the plugin".format(name)) + logger.exception("Got an error while trying to collect assets from {}, ignoring assets from the plugin".format(name), + extra=dict(plugin=name)) continue def asset_exists(category, asset): diff --git a/src/octoprint/server/util/sockjs.py b/src/octoprint/server/util/sockjs.py index 8423f7ca2..2e6fe9a3b 100644 --- a/src/octoprint/server/util/sockjs.py +++ b/src/octoprint/server/util/sockjs.py @@ -268,7 +268,8 @@ class PrinterStateConnection(octoprint.vendor.sockjs.tornado.SockJSConnection, o try: proceed = proceed and hook(self, self._user, type, payload) except: - self._logger.exception("Error processing emit hook handler from plugin {}".format(name)) + self._logger.exception("Error processing emit hook handler from plugin {}".format(name), + extra=dict(plugin=name)) if not proceed: return @@ -290,7 +291,8 @@ class PrinterStateConnection(octoprint.vendor.sockjs.tornado.SockJSConnection, o try: proceed = proceed and hook(self, self._user) except: - self._logger.exception("Error processing register hook handler for plugin {}".format(name)) + self._logger.exception("Error processing register hook handler for plugin {}".format(name), + extra=dict(plugin=name)) if not proceed: return @@ -358,7 +360,8 @@ class PrinterStateConnection(octoprint.vendor.sockjs.tornado.SockJSConnection, o try: hook(self, self._user) except: - self._logger.exception("Error processing authed hook handler for plugin {}".format(name)) + self._logger.exception("Error processing authed hook handler for plugin {}".format(name), + extra=dict(plugin=name)) def _on_logout(self): self._user = None @@ -367,5 +370,6 @@ class PrinterStateConnection(octoprint.vendor.sockjs.tornado.SockJSConnection, o try: hook(self, self._user) except: - self._logger.exception("Error processing authed hook handler for plugin {}".format(name)) + self._logger.exception("Error processing authed hook handler for plugin {}".format(name), + extra=dict(plugin=name)) diff --git a/src/octoprint/server/views.py b/src/octoprint/server/views.py index 0791997cf..b220e77ae 100644 --- a/src/octoprint/server/views.py +++ b/src/octoprint/server/views.py @@ -123,18 +123,22 @@ def in_cache(): ui_plugins = pluginManager.get_implementations(octoprint.plugin.UiPlugin, sorting_context="UiPlugin.on_ui_render") for plugin in ui_plugins: - if plugin.will_handle_ui(request): - ui = plugin._identifier - key = _cache_key(plugin._identifier, - url=url, - additional_key_data=plugin.get_ui_additional_key_data_for_cache) - unless = _preemptive_unless(url, additional_unless=plugin.get_ui_preemptive_caching_additional_unless) - data = _preemptive_data(plugin._identifier, - path=path, - base_url=base_url, - data=plugin.get_ui_data_for_preemptive_caching, - additional_request_data=plugin.get_ui_additional_request_data_for_preemptive_caching) - break + try: + if plugin.will_handle_ui(request): + ui = plugin._identifier + key = _cache_key(plugin._identifier, + url=url, + additional_key_data=plugin.get_ui_additional_key_data_for_cache) + unless = _preemptive_unless(url, additional_unless=plugin.get_ui_preemptive_caching_additional_unless) + data = _preemptive_data(plugin._identifier, + path=path, + base_url=base_url, + data=plugin.get_ui_data_for_preemptive_caching, + additional_request_data=plugin.get_ui_additional_request_data_for_preemptive_caching) + break + except Exception: + _logger.exception("Error while calling plugin {}, skipping it".format(plugin._identifier), + extra=dict(plugin=plugin._identifier)) else: ui = "_default" key = _cache_key("_default", url=url) @@ -403,13 +407,17 @@ def index(): # select view from plugins and fall back on default view if no plugin will handle it ui_plugins = pluginManager.get_implementations(octoprint.plugin.UiPlugin, sorting_context="UiPlugin.on_ui_render") for plugin in ui_plugins: - if plugin.will_handle_ui(request): - # plugin claims responsibility, let it render the UI - response = plugin_view(plugin) - if response is not None: - break - else: - _logger.warn("UiPlugin {} returned an empty response".format(plugin._identifier)) + try: + if plugin.will_handle_ui(request): + # plugin claims responsibility, let it render the UI + response = plugin_view(plugin) + if response is not None: + break + else: + _logger.warn("UiPlugin {} returned an empty response".format(plugin._identifier)) + except Exception: + _logger.exception("Error while calling plugin {}, skipping it".format(plugin._identifier), + extra=dict(plugin=plugin._identifier)) else: response = default_view() @@ -508,7 +516,9 @@ def fetch_template_data(refresh=False): try: result = hook(dict(template_sorting), dict(template_rules)) except: - _logger.exception("Error while retrieving custom template type definitions from plugin {name}".format(**locals())) + _logger.exception("Error while retrieving custom template type " + "definitions from plugin {name}".format(**locals()), + extra=dict(plugin=name)) else: if not isinstance(result, list): continue @@ -649,7 +659,8 @@ def fetch_template_data(refresh=False): wizard_required = implementation.is_wizard_required() wizard_ignored = octoprint.plugin.WizardPlugin.is_wizard_ignored(seen_wizards, implementation) except: - _logger.exception("Error while retrieving template data for plugin {}, ignoring it".format(name)) + _logger.exception("Error while retrieving template data for plugin {}, ignoring it".format(name), + extra=dict(plugin=name)) continue if not isinstance(vars, dict): diff --git a/src/octoprint/slicing/__init__.py b/src/octoprint/slicing/__init__.py index f9e60b0a2..7f80432bd 100644 --- a/src/octoprint/slicing/__init__.py +++ b/src/octoprint/slicing/__init__.py @@ -139,7 +139,8 @@ class SlicingManager(object): try: slicers[plugin.get_slicer_properties()["type"]] = plugin except: - self._logger.exception("Error while getting properties from slicer {}, ignoring it".format(plugin._identifier)) + self._logger.exception("Error while getting properties from slicer {}, ignoring it".format(plugin._identifier), + extra=dict(plugin=plugin._identifier)) continue self._slicers = slicers diff --git a/src/octoprint/timelapse.py b/src/octoprint/timelapse.py index 9b61a9481..a6dfaf597 100644 --- a/src/octoprint/timelapse.py +++ b/src/octoprint/timelapse.py @@ -79,7 +79,9 @@ def valid_timelapse(path): continue extensions += result except: - logging.getLogger(__name__).exception("Exception while retrieving additional timelapse extensions from hook {name}".format(name=name)) + logging.getLogger(__name__).exception("Exception while retrieving additional timelapse " + "extensions from hook {name}".format(name=name), + extra=dict(plugin=name)) _extensions = list(set(extensions)) diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index c64f13319..49d5a51fb 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -999,7 +999,8 @@ class MachineCom(object): try: retval = hook(self, "gcode", scriptName) except: - self._logger.exception("Error while processing hook {name}.".format(**locals())) + self._logger.exception("Error while processing hook {name}.".format(**locals()), + extra=dict(plugin=name)) else: if retval is None: continue @@ -1520,7 +1521,8 @@ class MachineCom(object): if parsedTemps is None or not parsedTemps: return except: - self._logger.exception("Error while processing temperatures in {}, skipping".format(name)) + self._logger.exception("Error while processing temperatures in {}, skipping".format(name), + extra=dict(plugin=name)) if current_tool_key in parsedTemps.keys(): shared_nozzle = self._printerProfileManager.get_current_or_default()["extruder"]["sharedNozzle"] @@ -1660,11 +1662,13 @@ class MachineCom(object): self._log("Disconnecting on request of the printer...") self._callback.on_comm_force_disconnect() else: - for hook in self._printer_action_hooks: + for name, hook in self._printer_action_hooks.items(): try: - self._printer_action_hooks[hook](self, line, action_command) + hook(self, line, action_command) except: - self._logger.exception("Error while calling hook {} with action command {}".format(self._printer_action_hooks[hook], action_command)) + self._logger.exception("Error while calling hook from plugin " + "{} with action command {}".format(name, action_command), + extra=dict(plugin=name)) continue if self._state not in (self.STATE_CONNECTING, self.STATE_DETECT_BAUDRATE): @@ -1908,7 +1912,8 @@ class MachineCom(object): try: hook(self, firmware_name, copy.copy(data)) except: - self._logger.exception("Error processing firmware info hook {}:".format(name)) + self._logger.exception("Error processing firmware info hook {}:".format(name), + extra=dict(plugin=name)) ##~~ Firmware capability report triggered by M115 elif lower_line.startswith("cap:"): @@ -1932,7 +1937,8 @@ class MachineCom(object): try: hook(self, capability, enabled, copy.copy(self._firmware_capabilities)) except: - self._logger.exception("Error processing firmware capability hook {}:".format(name)) + self._logger.exception("Error processing firmware capability hook {}:".format(name), + extra=dict(plugin=name)) ##~~ invalid extruder elif 'invalid extruder' in lower_line: @@ -2692,7 +2698,8 @@ class MachineCom(object): try: ret = hook(self, stripped_error) except: - self._logger.exception("Error while processing hook {name}:".format(**locals())) + self._logger.exception("Error while processing hook {name}:".format(**locals()), + extra=dict(plugin=name)) else: if ret: return line @@ -2750,7 +2757,8 @@ class MachineCom(object): try: ret = hook(self, ret) except Exception: - self._logger.exception("Error while processing hook {name}:".format(**locals())) + self._logger.exception("Error while processing hook {name}:".format(**locals()), + extra=dict(plugin=name)) else: if ret is None: return "" @@ -3209,7 +3217,9 @@ class MachineCom(object): try: hook_results = hook(self, phase, command, command_type, gcode, subcode=subcode, tags=tags) except: - self._logger.exception("Error while processing hook {name} for phase {phase} and command {command}:".format(**locals())) + self._logger.exception("Error while processing hook {name} for phase " + "{phase} and command {command}:".format(**locals()), + extra=dict(plugin=name)) else: normalized = _normalize_command_handler_result(command, command_type, gcode, subcode, tags, hook_results, @@ -3290,7 +3300,9 @@ class MachineCom(object): try: hook(self, phase, atcommand, parameters, tags=tags) except: - self._logger.exception("Error while processing hook {} for phase {} and command {}:".format(name, phase, atcommand)) + self._logger.exception("Error while processing hook {} for " + "phase {} and command {}:".format(name, phase, atcommand), + extra=dict(plugin=name)) # trigger built-in handler if available handler = getattr(self, "_atcommand_{}_{}".format(atcommand, phase), None)