diff --git a/src/octoprint/filemanager/__init__.py b/src/octoprint/filemanager/__init__.py index e54eb8054..c33f00c24 100644 --- a/src/octoprint/filemanager/__init__.py +++ b/src/octoprint/filemanager/__init__.py @@ -17,6 +17,7 @@ from .destinations import FileDestinations from .analysis import QueueEntry, AnalysisQueue from .storage import LocalFileStorage from .util import AbstractFileWrapper, StreamWrapper, DiskFileWrapper +from octoprint.util import get_fully_qualified_classname as fqcn from collections import namedtuple @@ -429,7 +430,8 @@ class FileManager(object): self._last_slicing_progress = progress_int for callback in self._slicing_progress_callbacks: try: callback.sendSlicingProgress(slicer, source_location, source_path, dest_location, dest_path, progress_int) - except: self._logger.exception("Exception while pushing slicing progress") + except: self._logger.exception("Exception while pushing slicing progress", + extra=dict(callback=fqcn(callback))) if progress_int: def call_plugins(slicer, source_location, source_path, dest_location, dest_path, progress): diff --git a/src/octoprint/filemanager/analysis.py b/src/octoprint/filemanager/analysis.py index cdb61b5a1..181320d16 100644 --- a/src/octoprint/filemanager/analysis.py +++ b/src/octoprint/filemanager/analysis.py @@ -19,6 +19,7 @@ import time from octoprint.events import Events, eventManager from octoprint.settings import settings from octoprint.util import monotonic_time +from octoprint.util import get_fully_qualified_classname as fqcn class QueueEntry(collections.namedtuple("QueueEntry", "name, path, type, location, absolute_path, printer_profile, analysis")): @@ -109,7 +110,11 @@ class AnalysisQueue(object): def _analysis_finished(self, entry, result): for callback in self._callbacks: - callback(entry, result) + try: + callback(entry, result) + except: + self._logger.exception(u"Error while pushing analysis data to callback {}".format(callback), + extra=dict(callback=fqcn(callback))) eventManager().fire(Events.METADATA_ANALYSIS_FINISHED, {"name": entry.name, "path": entry.path, "origin": entry.location, diff --git a/src/octoprint/printer/standard.py b/src/octoprint/printer/standard.py index 107ebebad..584cb23ea 100644 --- a/src/octoprint/printer/standard.py +++ b/src/octoprint/printer/standard.py @@ -30,6 +30,7 @@ from octoprint.util import comm as comm from octoprint.util import InvariantContainer from octoprint.util import to_unicode from octoprint.util import monotonic_time +from octoprint.util import get_fully_qualified_classname as fqcn class Printer(PrinterInterface, comm.MachineComPrintCallback): @@ -174,28 +175,32 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): try: callback.on_printer_add_temperature(data) except: - self._logger.exception(u"Exception while adding temperature data point to callback {}".format(callback)) + self._logger.exception(u"Exception while adding temperature data point to callback {}".format(callback), + extra=dict(callback=fqcn(callback))) def _sendAddLogCallbacks(self, data): for callback in self._callbacks: try: callback.on_printer_add_log(data) except: - self._logger.exception(u"Exception while adding communication log entry to callback {}".format(callback)) + self._logger.exception(u"Exception while adding communication log entry to callback {}".format(callback), + extra=dict(callback=fqcn(callback))) def _sendAddMessageCallbacks(self, data): for callback in self._callbacks: try: callback.on_printer_add_message(data) except: - self._logger.exception(u"Exception while adding printer message to callback {}".format(callback)) + self._logger.exception(u"Exception while adding printer message to callback {}".format(callback), + extra=dict(callback=fqcn(callback))) def _sendCurrentDataCallbacks(self, data): for callback in self._callbacks: try: callback.on_printer_send_current_data(copy.deepcopy(data)) except: - self._logger.exception(u"Exception while pushing current data to callback {}".format(callback)) + self._logger.exception(u"Exception while pushing current data to callback {}".format(callback), + extra=dict(callback=fqcn(callback))) #~~ callback from metadata analysis event @@ -1020,7 +1025,8 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): }) callback.on_printer_send_initial_data(data) except: - self._logger.exception("Error while trying to send initial state update") + self._logger.exception(u"Error while pushing initial state update to callback {}".format(callback), + extra=dict(callback=fqcn(callback))) def _getStateFlags(self): return self._dict(operational=self.is_operational(), diff --git a/src/octoprint/timelapse.py b/src/octoprint/timelapse.py index a6dfaf597..7550cc776 100644 --- a/src/octoprint/timelapse.py +++ b/src/octoprint/timelapse.py @@ -23,6 +23,7 @@ from octoprint.settings import settings from octoprint.events import eventManager, Events from octoprint.plugin import plugin_manager from octoprint.util import monotonic_time +from octoprint.util import get_fully_qualified_classname as fqcn import sarge import collections @@ -304,7 +305,8 @@ def notify_callbacks(timelapse): config = timelapse.config_data() for callback in _update_callbacks: try: callback.sendTimelapseConfig(config) - except: logging.getLogger(__name__).exception("Exception while pushing timelapse configuration") + except: logging.getLogger(__name__).exception("Exception while pushing timelapse configuration", + extra=dict(callback=fqcn(callback))) def configure_timelapse(config=None, persist=False): diff --git a/src/octoprint/users.py b/src/octoprint/users.py index 82a2fa290..124919a10 100644 --- a/src/octoprint/users.py +++ b/src/octoprint/users.py @@ -21,6 +21,7 @@ from builtins import range, bytes from octoprint.settings import settings as s from octoprint.util import atomic_write, to_bytes, deprecated, monotonic_time +from octoprint.util import get_fully_qualified_classname as fqcn class UserManager(object): valid_roles = ["user", "admin"] @@ -90,7 +91,8 @@ class UserManager(object): try: callback("login", user) except: - self._logger.exception("Error while calling login callback {!r}".format(callback)) + self._logger.exception("Error while calling login callback {!r}".format(callback), + extra=dict(callback=fqcn(callback))) return user @@ -122,7 +124,8 @@ class UserManager(object): try: callback("logout", user) except: - self._logger.exception("Error while calling logout callback {!r}".format(callback)) + self._logger.exception("Error while calling logout callback {!r}".format(callback), + extra=dict(callback=fqcn(callback))) def _cleanup_sessions(self): for session, user in self._session_users_by_session.items(): diff --git a/src/octoprint/util/__init__.py b/src/octoprint/util/__init__.py index 99e1250a9..7ed0fc68c 100644 --- a/src/octoprint/util/__init__.py +++ b/src/octoprint/util/__init__.py @@ -228,6 +228,25 @@ def get_class(name): raise ImportError("No module named " + name) +def get_fully_qualified_classname(o): + """ + Returns the fully qualified class name for an object. + + Based on https://stackoverflow.com/a/2020083 + + Args: + o: the object of which to determine the fqcn + + Returns: + (str) the fqcn of the object + """ + + module = getattr(o.__class__, "__module__", None) + if module is None: + return o.__class__.__name__ + return module + "." + o.__class__.__name__ + + def get_exception_string(): """ Retrieves the exception info of the last raised exception and returns it as a string formatted as