Skip to content

Improve error messages for YAML validation failures - #506

Open
XDGFX wants to merge 1 commit into
wireviz:devfrom
XDGFX:feature/better-error-messages
Open

XDGFX wants to merge 1 commit into
wireviz:devfrom
XDGFX:feature/better-error-messages

Conversation

@XDGFX

@XDGFX XDGFX commented Jun 16, 2026 •

Copy link
Copy Markdown

Closes #505

Summary

When a WireViz YAML file contains a mistake, errors currently surface as opaque Python tracebacks with no indication of which connector, cable, or connection set caused the failure. This PR improves error reporting in three areas:

  • wv_dataclasses.py: The style: simple pin count check now includes the connector's designator, the detected pin count, and a suggested fix rather than a bare message.
  • wv_harness.py: Two new explicit guards — one for a pin label resolving to an out-of-bounds index (previously an unhandled IndexError), and one for a connection referencing an undefined cable (previously a KeyError).
  • wireviz.py: Component generation and harness.connect() calls are wrapped to add context to any exception, identifying the connection set number and component names involved (e.g. "Error in connection set 3 (X1 → W1 → X2): ...").

These changes are purely additive to error handling and do not affect any output.

Test plan

  • Run existing examples to confirm no regressions in output — all 16 examples pass
  • Manually test a YAML with style: simple and multiple pins — error now reads: Connector 'X1' has style 'simple', which only supports one pin, but 3 pin(s) were specified. Either remove 'style: simple' or reduce to a single pin.
  • Manually test a YAML with mismatched pinlabels/pins length — error now reads: X1: pin label 'C' (index 2) has no corresponding pin number — connector has 2 pin(s) but 3 pinlabel(s).
  • Manually test a YAML referencing an undefined cable — error now reads: UNDEFINED_CABLE is an unknown template/designator/arrow. (caught at component generation, wrapped with connection set context)
  • Manually test a YAML with a bad template in a connection set — connection set number and names appear in the error: Error in connection set 1 (X1 → NONEXISTENT → X1): ...

- Connector with style 'simple' and multiple pins now reports connector
  name, actual pin count, and a suggested fix
- Pin label resolving to an out-of-bounds index raises a clear message
  instead of an IndexError
- Referencing an undefined cable raises a descriptive error instead of
  a KeyError
- Component generation and harness.connect() calls are wrapped with
  context identifying the connection set number and component names

Closes wireviz#505

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant