diff --git a/docs/events/index.rst b/docs/events/index.rst index a97e7e385..f2875c25d 100644 --- a/docs/events/index.rst +++ b/docs/events/index.rst @@ -338,6 +338,8 @@ PrintFailed * ``name``: the file's name * ``path``: the file's path within its storage location * ``origin``: the origin storage location of the file, either ``local`` or ``sdcard`` + * ``time``: the elapsed time of the print when it failed, in seconds (float) + * ``reason``: the reason the print failed, either ``cancelled`` or ``error`` .. deprecated:: 1.3.0 diff --git a/src/octoprint/printer/standard.py b/src/octoprint/printer/standard.py index 80cae7aa5..a3c589048 100644 --- a/src/octoprint/printer/standard.py +++ b/src/octoprint/printer/standard.py @@ -973,6 +973,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): payload = self._payload_for_print_job_event() if payload: payload["time"] = self._comm.getPrintTime() + payload["reason"] = "error" def finalize(): self._fileManager.log_print(payload["origin"], @@ -1103,8 +1104,14 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): self._stateMonitor.set_state(self._dict(text=self.get_state_string(), flags=self._getStateFlags())) - def on_comm_print_job_failed(self): + def on_comm_print_job_failed(self, reason=None): payload = self._payload_for_print_job_event() + + if reason: + payload["reason"] = reason + else: + payload["reason"] = "unknown" + if payload: eventManager().fire(Events.PRINT_FAILED, payload) @@ -1122,6 +1129,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): payload = self._payload_for_print_job_event(position=self._comm.cancel_position.as_dict() if self._comm and self._comm.cancel_position else None) if payload: payload["time"] = self._comm.getPrintTime() + payload["reason"] = "cancelled" eventManager().fire(Events.PRINT_CANCELLED, payload) if not suppress_script: diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index f6bd0e754..99cb3c073 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -3600,7 +3600,7 @@ class MachineComPrintCallback(object): def on_comm_print_job_started(self, suppress_script=False): pass - def on_comm_print_job_failed(self): + def on_comm_print_job_failed(self, reason=None): pass def on_comm_print_job_done(self, suppress_script=False):