aboutsummaryrefslogtreecommitdiffstats
path: root/klippy
diff options
context:
space:
mode:
Diffstat (limited to 'klippy')
-rw-r--r--klippy/extras/gcode_macro.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/klippy/extras/gcode_macro.py b/klippy/extras/gcode_macro.py
index 4f50c75a..78cdae0e 100644
--- a/klippy/extras/gcode_macro.py
+++ b/klippy/extras/gcode_macro.py
@@ -3,7 +3,7 @@
# Copyright (C) 2018-2021 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
-import traceback, logging, ast, copy
+import traceback, logging, ast, copy, json
import jinja2
@@ -144,12 +144,13 @@ class GCodeMacro:
prefix = 'variable_'
for option in config.get_prefix_options(prefix):
try:
- self.variables[option[len(prefix):]] = ast.literal_eval(
- config.get(option))
- except ValueError as e:
+ literal = ast.literal_eval(config.get(option))
+ json.dumps(literal, separators=(',', ':'))
+ self.variables[option[len(prefix):]] = literal
+ except (SyntaxError, TypeError, ValueError) as e:
raise config.error(
- "Option '%s' in section '%s' is not a valid literal" % (
- option, config.get_name()))
+ "Option '%s' in section '%s' is not a valid literal: %s" % (
+ option, config.get_name(), e))
def handle_connect(self):
prev_cmd = self.gcode.register_command(self.alias, None)
if prev_cmd is None:
@@ -169,8 +170,10 @@ class GCodeMacro:
raise gcmd.error("Unknown gcode_macro variable '%s'" % (variable,))
try:
literal = ast.literal_eval(value)
- except ValueError as e:
- raise gcmd.error("Unable to parse '%s' as a literal" % (value,))
+ json.dumps(literal, separators=(',', ':'))
+ except (SyntaxError, TypeError, ValueError) as e:
+ raise gcmd.error("Unable to parse '%s' as a literal: %s" %
+ (value, e))
v = dict(self.variables)
v[variable] = literal
self.variables = v