Skip to content

fix(oracle): make KiCadNotFound an environment fault, not exit 1 - #21

Merged
CameronBrooks11 merged 1 commit into
mainfrom
fix/18-doctor-exit-4
Sep 6, 2026
Merged

CameronBrooks11 merged 1 commit into
mainfrom
fix/18-doctor-exit-4

Conversation

@CameronBrooks11

Copy link
Copy Markdown
Member

KiCadNotFound and EnvironmentError_ were siblings, both RuntimeError. main
converts EnvironmentError_ to exit 4 in one place (cli.py:57), so a discovery
failure escaped that handler at any call site that did not wrap it itself.

check, gate and netlist survived only because each wraps the failure locally
(cli.py:172, :256, :319). doctor calls find_kicad_cli() directly at
cli.py:126, so nothing converted it.

Why exit 1 is the wrong code, specifically

Exit 1 is EXIT_VIOLATION -- the code reserved for "the design is wrong". A caller
that treats nonzero-but-not-4 as a finding read a missing KiCad as a bad board,
which is the exact confusion the exit codes exist to prevent. And it happened in the
one subcommand whose stated purpose is to tell you whether an engine can be found,
on the first command anyone runs on a new machine.

Verified

Reproduced on a PATH with no kicad-cli and no Flatpak, before:

$ netspec doctor
Traceback (most recent call last):
  ...
kicad_netspec.oracle.discovery.KiCadNotFound: no working kicad-cli found. ...
exit=1

After:

$ netspec doctor
error: no working kicad-cli found. Set NETSPEC_KICAD_CLI=/path/to/kicad-cli, ...

This is an environment problem, not a finding about your design.
exit=4

which now matches check / gate / netlist on the same machine.

Approach

Subclassing rather than wrapping inside _doctor, per the issue's suggested
direction: it fixes doctor and every future call site that reaches discovery
directly, where a local wrap would leave the next direct caller with the same bug.

test_oracle.py:22 already catches (KiCadNotFound, EnvironmentError_) as a tuple,
so it keeps working unchanged.

Tests

Three added to test_boundaries.py, where the structural invariants live: the
subclass relationship, doctor returning EXIT_ENVIRONMENT, and a parametrized
check that every engine-needing subcommand agrees on exit 4. All three confirmed to
go red with the source change reverted and the tests kept.

just check and just test green: 230 passed, 6 skipped (baseline 227).

Closes #18

KiCadNotFound and EnvironmentError_ were siblings, both RuntimeError.
main converts EnvironmentError_ to exit 4 in one place, so a discovery
failure escaped that handler at any call site that did not wrap it.

check, gate and netlist survived only because each wraps the failure
itself. doctor calls find_kicad_cli() directly, so nothing converted it:
it crashed with an unhandled traceback at exit 1 -- which is
EXIT_VIOLATION, the code reserved for "the design is wrong". A caller
treating nonzero-but-not-4 as a finding read a missing KiCad as a bad
board, which is the exact confusion the exit codes exist to prevent.
It is also the first command anyone runs on a new machine.

Subclassing fixes doctor and every future direct caller, rather than
only the one path a local wrap would cover.

Closes #18
@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown

Connectivity unchanged

tests/fixtures/good_ldo.kicad_sch

design sha256:36f119b0091afd2449fcd8cc92856510f5eda0d95156ad096fc1272a39cff90e

Connectivity unchanged.

tests/fixtures/polcap_rail_correct.kicad_sch

design sha256:60a7ddcc8a14c5b7c1269e499974c219ce6e3e3b53f22c734099aeb749c4b4b1

Connectivity unchanged.

Reported by netspec — KiCad's own netlist, not a guess.

@CameronBrooks11
CameronBrooks11 merged commit 668632a into main Sep 6, 2026
6 checks passed
@CameronBrooks11
CameronBrooks11 deleted the fix/18-doctor-exit-4 branch September 6, 2026 02:32
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.

netspec doctor exits 1 with a traceback when no KiCad is found, instead of the documented exit 4

1 participant