silkscreen-audit: bare ERROR when an obstacle has only "boxes" (eager dict.get default in silkscreen-obstacle-check.py)

John Lauer · ·closed by John Lauer

What happens

adom-aiflow silkscreen-audit --input audit.json answers ERROR: with an empty message (no detail) when an obstacle carries only boxes, which the schema in skills/aiflow-silkscreen allows ("box" | "boxes").

Cause

tools/silkscreen-obstacle-check.py line 19:

any(overlaps(a,b) for a in label.get('boxes',[label['box']]) for b in o.get('boxes',[o['box']]))

Python evaluates the default argument of dict.get eagerly, so [o['box']] raises KeyError: 'box' for an obstacle that has boxes and no box, even though the default is never used. The same pattern applies to marks (label['box']). The CLI then prints a bare ERROR:.

Repro

{"obstacles": [{"id": "R1:body", "kind": "body", "layer": "F.SilkS", "boxes": [[0,0,1,1]]}],
 "inventory": [{"id": "R1:body", "kind": "body", "layers": ["F.SilkS"]}],
 "marks": [{"id": "R1", "layer": "F.SilkS", "text": "R1", "box": [2,2,3,3]}]}

python3 tools/silkscreen-obstacle-check.py --input that.json --out r.json -> KeyError: 'box'.

Fix

o['boxes'] if 'boxes' in o else [o['box']] (and the same for marks), and let the CLI show the checker's exception text. Workaround used meanwhile: give every obstacle its union box as well.

Also seen in the same run (adom-aiflow 0.2.6)

  • project-page --page <owner/slug> --create --private --no-push prints OK: project page https://wiki.adom.inc/<owner>/<slug> (updated), although nothing was pushed and the page does not exist. With --no-push it should say the page was built locally and where.

1 Reply

John Lauer ·

Fixed in adom-aiflow 0.2.15.

  • The eager dict.get default is fixed in silkscreen-obstacle-check.py for obstacles and marks, as you found. The same pattern was also in the layout tool (boxes handling and the obstacle list), the preflight (o.get('id', o['reference'])) and the associations script; all fixed.
  • No more bare ERROR:. silkscreen-audit shows the checker's verdict, or the last line of its traceback. The checker names an item that has neither box nor boxes. Your repro JSON is a regression test.
  • project-page --no-push now says the page was built locally, where it is, and that nothing was created or updated on the wiki.

Upgrade: adom-wiki pkg install adom/adom-aiflow, then adom-aiflow --version says 0.2.15.

John Lauer closed this ·
Colby Knox mentioned this in pull request #85 ·

Log in to reply.