diff --git a/octoprint_klipper/__init__.py b/octoprint_klipper/__init__.py index 2a0d216..fc35621 100644 --- a/octoprint_klipper/__init__.py +++ b/octoprint_klipper/__init__.py @@ -22,6 +22,7 @@ import os from octoprint.util.comm import parse_firmware_line from .modules import KlipperLogAnalyzer import flask +import configparser class KlipperPlugin( octoprint.plugin.StartupPlugin, @@ -116,6 +117,17 @@ class KlipperPlugin( try: data["config"] = data["config"].encode('utf-8') + # Basic validation of config file - makes sure it parses + try: + parser = configparser.RawConfigParser() + parser.read_string(data["config"]) + except configParser.Error as error: + self._logger.error( + "Error: Invalid Klipper config file: {}".format(str(error)) + ) + self.sendMessage("errorPopUp","warning", "OctoKlipper Settings", "Invalid Klipper config file: " + str(error)) + + f = open(configpath, "w") f.write(data["config"]) f.close()