diff --git a/klippy/extras/gcode_macro.py b/klippy/extras/gcode_macro.py index 6d85f39f..6ee243c8 100644 --- a/klippy/extras/gcode_macro.py +++ b/klippy/extras/gcode_macro.py @@ -3,6 +3,7 @@ # Copyright (C) 2018 Kevin O'Connor # # This file may be distributed under the terms of the GNU GPLv3 license. +import logging class GCodeMacro: def __init__(self, config): @@ -19,9 +20,16 @@ class GCodeMacro: def cmd(self, params): if self.in_script: raise self.gcode.error("Macro %s called recursively" % (self.alias,)) + script = "" + try: + script = self.script.format(**params) + except Exception: + msg = "Macro %s script formatting failed" % (self.alias,) + logging.exception(msg) + raise self.gcode.error(msg) self.in_script = True try: - self.gcode.run_script_from_command(self.script) + self.gcode.run_script_from_command(script) finally: self.in_script = False