From c559d2cf562c7fdf5939a4a67a334a7d1882088c Mon Sep 17 00:00:00 2001 From: "Robert J. Heywood" Date: Mon, 3 Aug 2020 12:28:39 +0100 Subject: Rewind lorry FDs before parsing as JSON. First, the lorry files are parsed as YAML. If the parser fails, then the lorry files are parsed as JSON. If the YAML parser has advanced the Lorry file's file-descriptor, this can lead to JSON parser errors. This change resets the file descriptor to the start of the file before calling the JSON parser. --- lorrycontroller/readconf.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lorrycontroller/readconf.py b/lorrycontroller/readconf.py index 81b00f9..23dfff1 100644 --- a/lorrycontroller/readconf.py +++ b/lorrycontroller/readconf.py @@ -242,6 +242,7 @@ class ReadConfiguration(lorrycontroller.LorryControllerRoute): try: obj = yaml.safe_load(f) except yaml.YAMLError: + f.seek(0) obj = json.load(f) except ValueError as e: logging.error('YAML and JSON problem in %s', filename) -- cgit v1.2.1