Log JSON decode errors
This commit is contained in:
parent
9a84e191be
commit
cd1750b21a
|
@ -27,7 +27,11 @@ class Dashboard:
|
||||||
if w.get("multi"):
|
if w.get("multi"):
|
||||||
ts_list = LTS.find(w["data"][0])
|
ts_list = LTS.find(w["data"][0])
|
||||||
for ts in ts_list:
|
for ts in ts_list:
|
||||||
|
try:
|
||||||
tso = LTS(id=ts)
|
tso = LTS(id=ts)
|
||||||
|
except json.decoder.JSONDecodeError as e:
|
||||||
|
log.error("%s contains bad data: %s: Skipping", ts, e)
|
||||||
|
continue
|
||||||
if not tso.data:
|
if not tso.data:
|
||||||
log.warning("%s has no data: Skipping", tso.id)
|
log.warning("%s has no data: Skipping", tso.id)
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -41,6 +41,7 @@ class LTS:
|
||||||
with open(self.filename, "x+") as fh:
|
with open(self.filename, "x+") as fh:
|
||||||
fcntl.flock(fh, fcntl.LOCK_EX)
|
fcntl.flock(fh, fcntl.LOCK_EX)
|
||||||
json.dump({"description": self.description, "data": self.data}, fh)
|
json.dump({"description": self.description, "data": self.data}, fh)
|
||||||
|
log.info(f"Created {self.filename}")
|
||||||
self.rebuild_index()
|
self.rebuild_index()
|
||||||
except json.decoder.JSONDecodeError as e:
|
except json.decoder.JSONDecodeError as e:
|
||||||
log.exception(f"Cannot decode JSON in {self.filename}: {e}")
|
log.exception(f"Cannot decode JSON in {self.filename}: {e}")
|
||||||
|
@ -130,7 +131,11 @@ class LTS:
|
||||||
(_, _, hash) = fn.rpartition("/")
|
(_, _, hash) = fn.rpartition("/")
|
||||||
with open(fn, "r") as fh:
|
with open(fn, "r") as fh:
|
||||||
fcntl.flock(fh, fcntl.LOCK_SH)
|
fcntl.flock(fh, fcntl.LOCK_SH)
|
||||||
|
try:
|
||||||
d = json.load(fh)
|
d = json.load(fh)
|
||||||
|
except json.decoder.JSONDecodeError as e:
|
||||||
|
log.exception(f"Cannot decode JSON in {fn}: {e}")
|
||||||
|
raise
|
||||||
for k, v in d["description"].items():
|
for k, v in d["description"].items():
|
||||||
d1 = index.setdefault(k, {})
|
d1 = index.setdefault(k, {})
|
||||||
d2 = d1.setdefault(v, [])
|
d2 = d1.setdefault(v, [])
|
||||||
|
|
Loading…
Reference in New Issue