error_mcu: Rename "klippy:notify_mcu_shutdown" to "klippy:analyze_shutdown"

Rename the event to make it a little more clear what it is intended
for.  Also, check for an exception in each event handler.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor
2025-10-08 13:15:07 -04:00
parent 3215e3a2aa
commit f147804d97
2 changed files with 8 additions and 4 deletions

View File

@@ -62,8 +62,8 @@ class PrinterMCUError:
def __init__(self, config):
self.printer = config.get_printer()
self.clarify_callbacks = {}
self.printer.register_event_handler("klippy:notify_mcu_shutdown",
self._handle_notify_mcu_shutdown)
self.printer.register_event_handler("klippy:analyze_shutdown",
self._handle_analyze_shutdown)
self.printer.register_event_handler("klippy:notify_mcu_error",
self._handle_notify_mcu_error)
def add_clarify(self, msg, callback):
@@ -88,7 +88,7 @@ class PrinterMCUError:
newmsg = "%s%s%s%s%s" % (prefix, mcu_msg, clarify_msg,
hint, message_shutdown)
self.printer.update_error_msg(msg, newmsg)
def _handle_notify_mcu_shutdown(self, msg, details):
def _handle_analyze_shutdown(self, msg, details):
if msg == "MCU shutdown":
self._check_mcu_shutdown(msg, details)
else:

View File

@@ -213,7 +213,11 @@ class Printer:
logging.exception("Exception during shutdown handler")
logging.info("Reactor garbage collection: %s",
self.reactor.get_gc_stats())
self.send_event("klippy:notify_mcu_shutdown", msg, details)
for cb in self.event_handlers.get("klippy:analyze_shutdown", []):
try:
cb(msg, details)
except:
logging.exception("Exception during analyze_shutdown handler")
def invoke_async_shutdown(self, msg, details={}):
self.reactor.register_async_callback(
(lambda e: self.invoke_shutdown(msg, details)))