From f31f3fdd68432cce978a8442c3cb855296121f51 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Tue, 12 Nov 2024 11:55:35 -0600 Subject: [PATCH] scripts: csv.py: Fixed missing fields going undetected There's a bit of a push and pull when it comes to typechecking CSV fields in our scripts. On one hand, we want the flexibility to accepts scripts with various mismatched fields, on the other hand, we _really_ want to know if a typo caused a field to be quietly replaced with all zeros... I _think_ it's safe to say: if no fields across _all_ input files match a requested field, we should error. But I may end up wrong about this. Worst case we can always revert in the future, maybe with an explicit flag to ignore missing fields. --- scripts/csv.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/csv.py b/scripts/csv.py index 0f24a1ac..81dcb8d1 100755 --- a/scripts/csv.py +++ b/scripts/csv.py @@ -1117,6 +1117,11 @@ def infer(fields_, results, for k in fields)) types = {} for k in fields__: + if k not in fields_: + print("error: no field %r?" % k, + file=sys.stderr) + sys.exit(2) + for t in [RInt, RFloat, RFrac]: for r in results: if k in r and r[k].strip(): @@ -1130,7 +1135,7 @@ def infer(fields_, results, else: print("error: no type matches field %r?" % k, file=sys.stderr) - sys.exit(-1) + sys.exit(2) # typecheck field exprs, note these may reference input fields # with the same name