Skip to content

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

Closed

Description

@CameronBrooks11

netspec doctor is the one subcommand whose stated purpose is "check that a KiCad engine can be found and run". It is also the only one that crashes when the answer is no.

Reproduction

kicad-netspec 0.7.0, installed with uv tool install kicad-netspec, on Debian 13 / Python 3.12. Run with a PATH that has no kicad-cli and no Flatpak:

$ mkdir -p /tmp/m/bin && ln -s "$(command -v python3)" /tmp/m/bin/python3 \
    && ln -s "$(command -v netspec)" /tmp/m/bin/netspec
$ PATH=/tmp/m/bin netspec doctor
Traceback (most recent call last):
  File ".../bin/netspec", line 10, in <module>
    sys.exit(main())
  File ".../kicad_netspec/cli.py", line 53, in main
    return int(args.handler(args))
  File ".../kicad_netspec/cli.py", line 126, in _doctor
    cli = find_kicad_cli()
  File ".../kicad_netspec/oracle/discovery.py", line 85, in find_kicad_cli
    raise KiCadNotFound(
$ echo $?
1

Same environment, the other subcommands behave as documented:

netspec check    exit 4   handled, "This is an environment problem, not a finding about your design."
netspec gate     exit 4   handled
netspec netlist  exit 4   handled
netspec doctor   exit 1   unhandled traceback

Expected

Exit 4 with the environment-fault message, the same as check / gate / netlist.

Cause

KiCadNotFound and EnvironmentError_ are siblings, not parent and child:

oracle/discovery.py:34   class KiCadNotFound(RuntimeError)
oracle/base.py:29        class EnvironmentError_(RuntimeError)
cli.py:54                except EnvironmentError_ as exc:  ->  return EXIT_ENVIRONMENT
>>> issubclass(KiCadNotFound, EnvironmentError_)
False

The other handlers survive because they wrap the failure themselves (cli.py:172, :256, :319 each raise EnvironmentError_(str(exc)) from exc). _doctor calls find_kicad_cli() directly at cli.py:126, so nothing converts it.

Why this one matters more than the exit code suggests

The contract's own distinction is between "could not tell" and "the design is wrong", and exit 4 is how that is communicated. A traceback and exit 1 is indistinguishable to a caller from a crash, and 1 is EXIT_VIOLATION — so a script that treats nonzero-but-not-4 as "a finding" reads a missing KiCad as a bad board. That is the precise confusion the exit codes exist to prevent, occurring in the diagnostic command.

It is also the first command anyone runs on a new machine, so it is the worst place for a traceback.

Suggested fix

Making KiCadNotFound subclass EnvironmentError_ fixes _doctor and any future call site that reaches discovery directly, rather than only the one path. Wrapping inside _doctor also works but leaves the next direct caller with the same bug.

Happy to send a PR if the subclass direction is the one you want.

Activity

  1. added 2 commits that reference this issue on Sep 6, 2026
    668632a
    fbd8fe0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions