🚧 Error handling works now

This commit is contained in:
Gina Häußge committed 2019-07-30 15:57:36 +02:00
1 parent dd6ca9d351
commit 16cff1a098
3 files changed
+44 -4

No files matched your search

+1 -1
View File
@@ -117,7 +117,7 @@ class Printjob(with_metaclass(ABCMeta, ProtocolListener, ListenerAware)):
def resume(self, user=None, tags=None, **kwargs):
self.process_job_resumed(user=user, tags=tags, **kwargs)
def cancel(self, error=False, user=None, tags=None, **kwargs):
def cancel(self, error=None, user=None, tags=None, **kwargs):
if error:
self.process_job_failed(**kwargs)
else:
+24 -2
View File
@@ -349,6 +349,8 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt
long=kwargs.get("timeouts", dict()).get("max_consecutive_long", 5),
)
self.firmware_errors = kwargs.get("error_handling", dict()).get("firmware_errors", "disconnect")
flavor_comm_attrs = self.get_flavor_attributes_starting_with(self.flavor, "comm_")
flavor_message_attrs = self.get_flavor_attributes_starting_with(self.flavor, "message_")
flavor_error_attrs = self.get_flavor_attributes_starting_with(self.flavor, "error_")
@@ -567,7 +569,7 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt
self.send_commands(SendQueueMarker(finalize), part_of_job=True)
self._continue_sending()
def cancel_processing(self, error=False, user=None, tags=None, log_position=True):
def cancel_processing(self, error=None, user=None, tags=None, log_position=True):
if self.state not in ProtocolState.PROCESSING_STATES + (ProtocolState.PAUSED,):
return
@@ -604,6 +606,7 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt
self._job.cancel(error=error, user=user, tags=tags)
self.notify_listeners("on_protocol_job_cancelling", self, self._job,
error=error,
user=user,
tags=tags)
@@ -1539,7 +1542,20 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt
# unknown error message
self.error = line
# TODO error handling
if self.firmware_errors != "ignore":
if self.firmware_errors == "disconnect" or self.flavor.error_sdcard(line, lower_line, error, self._state, self._protected_flags):
# disconnect
self._trigger_error(error, "firmware")
elif self._state in ProtocolState.PROCESSING_STATES:
# cancel the print
self.cancel_processing(error=error)
self._clear_to_send.set()
else:
self._to_logfile_with_terminal("WARNING! Received an error from the printer's firmware, ignoring that as configured "
"but you might want to investigate what happened here! Error: {}".format(error))
self._clear_to_send.set()
def _on_error_communication(self, error_type):
self._last_communication_error = error_type
@@ -2629,3 +2645,9 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt
self._registered_messages = flavor_comm_attrs + flavor_message_attrs
self._current_registered_messages = self._registered_messages
self._error_messages = flavor_error_attrs
def _trigger_error(self, text, reason, disconnect=True):
self.state = ProtocolState.ERROR
self._event_bus.fire(Events.ERROR, dict(error=text, reason=reason))
if disconnect:
self.disconnect(error=True)
@@ -200,7 +200,25 @@ class GenericFlavor(with_metaclass(FlavorMeta, object)):
@classmethod
def error_communication(cls, line, lower_line, error, state, flags):
return "line number" in lower_line or "checksum" in lower_line or "format error" in lower_line or "expected line" in lower_line
return any(map(lambda x: x in lower_line, ("line number",
"checksum",
"format error",
"expected line")))
@classmethod
def error_sdcard(cls, line, lower_line, error, state, flags):
return any(map(lambda x: x in lower_line, ("volume.init",
"openroot",
"workdir",
"error writing to file",
"cannot open",
"open failed",
"cannot enter")))
@classmethod
def error_fatal(cls, line, lower_line, error, state, flags):
return any(map(lambda x: x in lower_line, ("kill() called",
"fatal:")))
@classmethod
def message_temperature(cls, line, lower_line, state, flags):