Add type check to validation job

This commit is contained in:
Marco Realacci 2024-06-14 14:47:12 +02:00
parent 5b49781fa6
commit 7650531641

View file

@ -22,11 +22,12 @@ for filename in os.listdir("data/questions"):
raise Exception(str(data.index(q)) + ": Question has no answers.")
for a in q["answers"]:
if a["text"] == "" and a["image"] == "":
raise Exception(str(data.index(q)) + ": Answer's text and image cannot both be empty.")
if type(a["text"]) is not str or type(a["image"]) is not str:
raise Exception(str(data.index(q)) + ": Some answer's parameters are null, missing or their type is wrong.")
if a["text"] == "" and a["image"] == "":
raise Exception(str(data.index(q)) + ": Answer's text and image cannot both be empty.")
except Exception as e:
logging.error(getattr(e, 'message', repr(e)))
logging.fatal(filename + " is invalid. Aborting.")