summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert J. Heywood <robert.heywood@codethink.co.uk>2020-08-03 12:28:39 +0100
committerRobert J. Heywood <robert.heywood@codethink.co.uk>2020-08-03 14:13:08 +0100
commitc559d2cf562c7fdf5939a4a67a334a7d1882088c (patch)
tree7dac03902bdc6955b93d751370c72ce325f5a81c
parentab010fb032b7f75212140ecb7b31e1a96f50a621 (diff)
downloadlorry-controller-c559d2cf562c7fdf5939a4a67a334a7d1882088c.tar.gz
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.
-rw-r--r--lorrycontroller/readconf.py1
1 files changed, 1 insertions, 0 deletions
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)