Fix firmware error reporting on job cancel

Closes #2364
This commit is contained in:
Gina Häußge committed 2018-02-26 12:47:46 +01:00
1 parent c3ba9c8453
commit b3fff6e95f
5 files changed
+82 -24

No files matched your search

+11 -1
View File
@@ -363,8 +363,18 @@ PrintDone
Still available for reasons of backwards compatibility. Will be removed with 1.4.0.
PrintCancelling
The print is about to be cancelled.
Payload:
* ``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``
* ``firmwareError``: the firmware error that caused cancelling the print job, if any
PrintCancelled
The print has been cancelled via the cancel button.
The print has been cancelled.
Payload:
+1
View File
@@ -69,6 +69,7 @@ class Events(object):
PRINT_STARTED = "PrintStarted"
PRINT_DONE = "PrintDone"
PRINT_FAILED = "PrintFailed"
PRINT_CANCELLING = "PrintCancelling"
PRINT_CANCELLED = "PrintCancelled"
PRINT_PAUSED = "PrintPaused"
PRINT_RESUMED = "PrintResumed"
+7
View File
@@ -1163,6 +1163,13 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
payload = self._payload_for_print_job_event()
eventManager().fire(Events.PRINT_FAILED, payload)
def on_comm_print_job_cancelling(self, firmware_error=None):
payload = self._payload_for_print_job_event()
if payload:
if firmware_error:
payload["firmwareError"] = firmware_error
eventManager().fire(Events.PRINT_CANCELLING, payload)
def on_comm_print_job_cancelled(self):
self._setCurrentZ(None)
self._updateProgressData()
+49 -14
View File
@@ -225,28 +225,63 @@ function DataUpdater(allViewModels, connectCallback, disconnectCallback) {
log.debug("Got event " + type + " with payload: " + JSON.stringify(payload));
if (type == "PrintCancelled") {
if (payload.firmwareError) {
new PNotify({
title: gettext("Unhandled communication error"),
text: _.sprintf(gettext("There was an unhandled error while talking to the printer. Due to that the ongoing print job was cancelled. Error: %(firmwareError)s"), payload),
type: "error",
hide: false
});
if (type === "PrintCancelling" && payload.firmwareError) {
new PNotify({
title: gettext("Error reported by printer"),
text: _.sprintf(gettext("Your printer's firmware reported an error. Due to that the ongoing print job will be cancelled. Reported error: %(firmwareError)s"), payload),
type: "error",
hide: false
});
} else if (type === "Error" && payload.error) {
var title = undefined,
text = undefined;
switch (payload.reason) {
case "firmware": {
title = gettext("Error reported by printer");
text = _.sprintf(gettext("Your printer's firmware reported an error. Due to that OctoPrint will disconnect. Reported error: %(error)s"), payload);
break;
}
case "resend":
case "timeout": {
title = gettext("Communication error");
text = gettext("There was a communication error while talking to your printer. Please consult the terminal output and octoprint.log for details. Error: %(error)s", payload);
break;
}
case "connection": {
title = gettext("Error connecting to printer");
text = gettext("There was an error while trying to connect to your printer. Error: %(error)s", payload);
break;
}
case "start_print": {
title = gettext("Error starting a print");
text = gettext("There was an error while trying to start a print job. Error: %(error)s", payload);
break;
}
case "autodetect_port":
case "autodetect_baudrate": {
// ignore
break;
}
default: {
title = gettext("Unknown error");
text = gettext("There was an unknown error while talking to your printer. Please consult the terminal output and octoprint.log for details. Error: %(error)s", payload);
break;
}
}
} else if (type == "Error") {
if (payload.error && payload.error.indexOf("autodetect") == -1) { // ignore "failed to autodetect"
if (title && text) {
new PNotify({
title: gettext("Unhandled communication error"),
text: _.sprintf(gettext("There was an unhandled error while talking to the printer. Due to that OctoPrint disconnected. Error: %(error)s"), payload),
title: title,
text: text,
type: "error",
hide: false
});
}
} else if (type == "PrinterReset") {
} else if (type === "PrinterReset") {
new PNotify({
title: gettext("Printer reset detected"),
text: gettext("It looks like the printer was reset while a connection was active. If this was intentional you may safely ignore this message. Otherwise you should investigate why your printer reset itself, since this will interrupt prints and also file transfers to your printer's SD."),
text: gettext("It looks like your printer reset while a connection was active. If this was intentional you may safely ignore this message. Otherwise you should investigate why your printer reset itself, since this will interrupt prints and also file transfers to your printer's SD."),
hide: false
});
}
+14 -9
View File
@@ -953,7 +953,7 @@ class MachineCom(object):
self._logger.exception("Error while trying to start printing")
self._errorValue = get_exception_string()
self._changeState(self.STATE_ERROR)
eventManager().fire(Events.ERROR, {"error": self.getErrorString()})
eventManager().fire(Events.ERROR, {"error": self.getErrorString(), "reason": "start_print"})
def startFileTransfer(self, filename, localFilename, remoteFilename, special=False, tags=None):
if not self.isOperational() or self.isBusy():
@@ -1040,7 +1040,7 @@ class MachineCom(object):
self._currentFile = None
self._callback.on_comm_file_selected(None, None, False)
def _cancel_preparation_done(self):
def _cancel_preparation_done(self, firmware_error=None):
self._recordFilePosition()
self._callback.on_comm_print_job_cancelled()
@@ -1067,6 +1067,8 @@ class MachineCom(object):
self._record_cancel_data = True
self.sendCommand("M114", tags=tags | {"trigger:comm.cancel", "trigger:record_position"})
self._callback.on_comm_print_job_cancelling(firmware_error=firmware_error)
with self._jobLock:
self._changeState(self.STATE_OPERATIONAL)
@@ -1724,7 +1726,7 @@ class MachineCom(object):
self.close(wait=False)
self._errorValue = "No more baudrates to test, and no suitable baudrate found."
self._changeState(self.STATE_ERROR)
eventManager().fire(Events.ERROR, {"error": self.getErrorString()})
eventManager().fire(Events.ERROR, {"error": self.getErrorString(), "reason": "autodetect_baudrate"})
elif 'start' in line or 'ok' in line:
self._onConnected()
if 'start' in line:
@@ -1774,7 +1776,7 @@ class MachineCom(object):
errorMsg = "See octoprint.log for details"
self._log(errorMsg)
self._errorValue = errorMsg
eventManager().fire(Events.ERROR, {"error": self.getErrorString()})
eventManager().fire(Events.ERROR, {"error": self.getErrorString(), "reason": "crash"})
self.close(is_error=True)
self._log("Connection closed, closing down monitor")
@@ -1831,7 +1833,7 @@ class MachineCom(object):
self._logger.info(message)
self._log(message + " " + general_message)
self._errorValue = "Too many consecutive timeouts, printer still connected and alive?"
eventManager().fire(Events.ERROR, {"error": self._errorValue})
eventManager().fire(Events.ERROR, {"error": self._errorValue, "reason": "timeout"})
self.close(is_error=True)
elif self._resendActive:
@@ -2092,7 +2094,7 @@ class MachineCom(object):
if port is None:
self._errorValue = 'Failed to autodetect serial port, please set it manually.'
self._changeState(self.STATE_ERROR)
eventManager().fire(Events.ERROR, {"error": self.getErrorString()})
eventManager().fire(Events.ERROR, {"error": self.getErrorString(), "reason": "autodetect_port"})
self._log("Failed to autodetect serial port, please set it manually.")
return None
@@ -2125,7 +2127,7 @@ class MachineCom(object):
exception_string = get_exception_string()
self._errorValue = "Connection error, see Terminal tab"
self._changeState(self.STATE_ERROR)
eventManager().fire(Events.ERROR, {"error": self.getErrorString()})
eventManager().fire(Events.ERROR, {"error": self.getErrorString(), "reason": "connection"})
error_message = "Unexpected error while connecting to serial port: %s %s (hook %s)" % (self._port, exception_string, name)
self._log(error_message)
@@ -2198,7 +2200,7 @@ class MachineCom(object):
if self._disconnect_on_errors:
self._errorValue = error_text
self._changeState(self.STATE_ERROR)
eventManager().fire(Events.ERROR, {"error": self.getErrorString()})
eventManager().fire(Events.ERROR, {"error": self.getErrorString(), "reason": "firmware"})
elif self.isPrinting():
self.cancelPrint(firmware_error=error_text)
self._clear_to_send.set()
@@ -2333,7 +2335,7 @@ class MachineCom(object):
if self.isPrinting():
# abort the print, there's nothing we can do to rescue it now
self._changeState(self.STATE_ERROR)
eventManager().fire(Events.ERROR, {"error": self.getErrorString()})
eventManager().fire(Events.ERROR, {"error": self.getErrorString(), "reason": "resend"})
else:
# reset resend delta, we can't do anything about it
self._resendDelta = None
@@ -3013,6 +3015,9 @@ class MachineComPrintCallback(object):
def on_comm_print_job_done(self):
pass
def on_comm_print_job_cancelling(self, firmware_error=None):
pass
def on_comm_print_job_cancelled(self):
pass