diff --git a/docs/events/index.rst b/docs/events/index.rst index 71c8dcc2b..bb8e9b07d 100644 --- a/docs/events/index.rst +++ b/docs/events/index.rst @@ -201,6 +201,14 @@ Error Payload: * ``error``: the error string + * ``reason``: the reason for the error, one of ``firmware``, ``resend``, ``resend_loop``, ``timeout``, + ``connection``, ``start_print``, ``autodetect`` or unset. + * ``m112``: whether this error will cause an emergency stop command ``M112`` to be sent to the printer + + In case of errors with reason ``firmware``, the following additional fields might be present in the payload: + + * ``faq``: a link to the FAQ entry for the error + * ``log``: the last lines from the communication log PrinterStateChanged The state of the printer changed. diff --git a/src/octoprint/static/js/app/dataupdater.js b/src/octoprint/static/js/app/dataupdater.js index c9bb3f3e7..dd53c5a7f 100644 --- a/src/octoprint/static/js/app/dataupdater.js +++ b/src/octoprint/static/js/app/dataupdater.js @@ -337,6 +337,46 @@ function DataUpdater(allViewModels, connectCallback, disconnectCallback) { ), {error: _.escape(payload.error)} ); + + const modal = $("#firmwareErrorModal"); + if (modal.length) { + $("#firmwareErrorModalError", modal).text(payload.error); + + if (payload.m112) { + $("#firmwareErrorModalDisconnect", modal).hide(); + $("#firmwareErrorModalM112", modal).show(); + } else { + $("#firmwareErrorModalDisconnect", modal).show(); + $("#firmwareErrorModalM112", modal).hide(); + } + + if (payload.faq) { + $("#firmwareErrorModalFaq a", modal).attr( + "href", + "https://faq.octoprint.org/" + payload.faq + ); + $("#firmwareErrorModalFaq", modal).show(); + } else { + $("#firmwareErrorModalFaq", modal).hide(); + } + + const log = $("#firmwareErrorModalLog", modal); + if (payload.log) { + log.empty(); + _.each(payload.log, (line) => { + log.append( + '' + + _.escape(line) + + "\n" + + "" + ); + }); + } + + modal.modal("show"); + log.scrollTop(log.prop("scrollHeight")); + } + break; } case "resend": diff --git a/src/octoprint/templates/dialogs/firmwareerror.jinja2 b/src/octoprint/templates/dialogs/firmwareerror.jinja2 new file mode 100644 index 000000000..ea7ae4831 --- /dev/null +++ b/src/octoprint/templates/dialogs/firmwareerror.jinja2 @@ -0,0 +1,34 @@ +
diff --git a/src/octoprint/templates/index.jinja2 b/src/octoprint/templates/index.jinja2 index 69ddb0a45..100981d06 100644 --- a/src/octoprint/templates/index.jinja2 +++ b/src/octoprint/templates/index.jinja2 @@ -174,6 +174,7 @@ {% include 'dialogs/files.jinja2' %} {% include 'dialogs/temperature.jinja2' %} {% include 'dialogs/timelapse.jinja2' %} + {% include 'dialogs/firmwareerror.jinja2' %} diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 0a6e1d8bd..d9a1c08c8 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -4072,18 +4072,53 @@ class MachineCom: def _trigger_error(self, text, reason, close=True): self._errorValue = text self._changeState(self.STATE_ERROR) - eventManager().fire( - Events.ERROR, {"error": self.getErrorString(), "reason": reason} + + trigger_m112 = ( + self._send_m112_on_error + and not self.isSdPrinting() + and reason not in ("connection", "autodetect") ) + + payload = self._payload_for_error(reason, close and trigger_m112) + eventManager().fire(Events.ERROR, payload) + if close: - if ( - self._send_m112_on_error - and not self.isSdPrinting() - and reason not in ("connection", "autodetect") - ): + if trigger_m112: self._trigger_emergency_stop(close=False) self.close(is_error=True) + _error_faqs = { + "mintemp": ("mintemp",), + "maxtemp": ("maxtemp",), + "thermal-runaway": ("runaway",), + "heating-failed": ("heating failed",), + "probing-failed": ( + "probing failed", + "bed leveling", + "reference point", + "bltouch", + ), + } + + def _payload_for_error(self, reason, trigger_m112): + error = self.getErrorString() + payload = { + "error": error, + "reason": reason, + "m112": trigger_m112, + } + + if reason == "firmware": + payload["log"] = list(self._terminal_log) + + error_lower = error.lower() + for faq, triggers in self._error_faqs.items(): + if any(trigger in error_lower for trigger in triggers): + payload["faq"] = "firmware-" + faq + break + + return payload + def _readline(self): if self._serial is None: return None