Repository navigation
Description
Context & Rationale
src/devops_cli/exceptions/ is 88 classes and 2,426 lines whose interface equals its implementation. Checked at 9c879ae.
- Every class has an
__init__, but 87 of 88 only forward keyword arguments to the base; onlyDevOpsCLIError(base.py, 56 lines) has behaviour (secret masking,__str__,to_dict). - 32 classes are never raised in
src, 57 are never caught by name, 35 are raised from exactly one module; 47 appear inpytest.raises. - Error codes come three ways: 36 via
CONST_ERROR_CODE_*(42 constants whose only importer is this package), 14 inline literals, 5DEFAULT_ERROR_CODEclass attributes, 3 of which duplicate the literal passed tosuper(). - The exit seam (
except DevOpsCLIError→typer.Exit(exc.exit_code)) lives incore/command_decorator.py::cli_command_handler, which no command module imports (docs: hand-written docs name only commands, options and components that exist #921). 19 hand-rolledraise typer.Exit(code=exc.exit_code)sites exist, 9 of them incommands/cloudflare.py.
Deletion test: delete the 87 __init__s and nothing reappears, callers already pass the kwargs the base accepts; delete the 32 never-raised classes and nothing reappears.
Scope & Deliverables
- Deliverable:
error_codeandexit_codeare class attributes read by the base__init__; domain bases (KubernetesError,VaultError, ...) add only their structured-detail keys; never-raised classes go; one exit seam applied bynew_typerreplaces the 19 hand-rolled sites; theCONST_ERROR_CODE_*constants come home as class data (they are identities, not matching lists). - Tests:
test_exceptions.py::test_one_error_code_maps_to_one_exit_statusbecomes a table check; the 47pytest.raisessites are unchanged;test_domain_specific_exceptions_existshrinks with the deleted classes. - Key questions (open):
- Does
cli_command_handlerbecome the seam every command passes through, or doesnew_typercarry it? - One sentence for AGENTS.md: exit and error codes live on the exception class.
- Does
- Constraint: feat(cli): blind exception handling policy #423 (blind exception handling) is about
exceptsites, not the taxonomy; the two do not overlap.
Strategic Alignment
- Design: none
- Depends on: none
- Related: feat(cli): blind exception handling policy #423, docs: hand-written docs name only commands, options and components that exist #921, refactor(config): the config barrel and the unused config names go, and the package inits stop re-exporting #776
- Source: architecture review of 2026-10-02, config and language cross-cut
Scope added 2026-10-02: checked at 38517a8. A second exit seam exists: #945 (6e5bb1f) added exit_on_error (core/cli.py:187-200), which prints the error without a traceback and exits with its exit_code. It is used 8 times (commands/rag.py 5, commands/ai_ingest.py 3). The hand-rolled raise typer.Exit(... exc.exit_code) sites are 20, not 19: commands/cloudflare.py 9, commands/valkey.py 9, commands/sandbox.py:979 and commands/telemetry.py:523. Five more typer.Exit(<result>.exit_code) lines pass a subprocess or verdict result and are not exception sites. Every command except the config group passes through OTelTyper.command, which wraps it in _execute_traced_cli_command (core/cli.py:76-106, :159-172). commands/config.py:45 builds a plain typer.Typer. AGENTS.md:393 names CONST_ERROR_CODE_*, and so does docs/SDLC.md:130-132. ai/instruction_generator.py has no counterpart, and AGENTS.md is curated, not generated (#840). ARCHITECTURE.md:167-172 describes @cli_command_handler on every command; #921 (v0.2.28) rewrites that text to describe new_typer().
Acceptance criteria
-
DevOpsCLIErrorreadserror_codeandexit_codefrom class attributes. The__init__methods that only forward keyword arguments are deleted, and domain bases add only their structured-detail keys. - Classes never raised in
srcare deleted. The PR lists them with the search that shows no raise. - The
CONST_ERROR_CODE_*constants (40 inconfig/constants.pyat 38517a8, not 42) become class data, andconfig/constants.pykeeps none of them. - The wrapper in
OTelTyper.commandis the one exit seam. It reports aDevOpsCLIErrorwithprint_error(exc.message, safe=True)and exits withexc.exit_code.cli_command_handler(core/command_decorator.py),exit_on_error, the 20 hand-rolled sites and the 8exit_on_errorblocks are deleted. - A test registers a command on
new_typer()that raises aDevOpsCLIErrorsubclass whose message holds Rich markup. It asserts the exit code, one error line, escaped markup and no traceback. -
tests/test_exceptions.py::test_one_error_code_maps_to_one_exit_statuschecks a table built from the class hierarchy. -
commands/config.pybuilds its app withnew_typer(), so every command passes through the seam. A test walks the registered apps and finds no plaintyper.Typer. - AGENTS.md:393 and
docs/SDLC.md:130-132are edited in place to say that an exception class declares itserror_codeandexit_code. AGENTS.md is not regenerated (docs(agents): instruction surfaces state only what is true, anddevops ai agentsnever overwrites AGENTS.md #840).ARCHITECTURE.mdnamesOTelTyper.commandas the exit seam and no longer namescli_command_handler. -
docs/ERRORS.mdis regenerated (docs/generator.py:1051) and lists the same codes and exit statuses as before. - The new and changed tests run offline, with no model, network or cluster.
-
uv run devops cipasses. - (person-run)
devops cloudflareanddevops ragcommands that fail on a missing token print one error line and exit with the same code as before.
Key questions
- Does
cli_command_handlerbecome the seam every command passes through, or doesnew_typercarry it? (proposed)new_typercarries it, inOTelTyper.command's wrapper, which every command except theconfiggroup already passes through; this item movesconfigontonew_typer(). A decorator can be forgotten; the wrapper cannot.cli_command_handler(no command uses it; onlycore/__init__.py:36exports it andtests/test_command_decorator.pytests it) andexit_on_errorboth go. - One sentence for AGENTS.md: exit and error codes live on the exception class. (proposed) "An exception class declares its
error_codeandexit_code; a command raises it, and the command seam reports it and exits." It replaces theCONST_ERROR_CODE_*clause of AGENTS.md:393 anddocs/SDLC.md:132, edited in place. AGENTS.md is curated:devops ai agentswould write its short template over it (docs(agents): instruction surfaces state only what is true, anddevops ai agentsnever overwrites AGENTS.md #840). - Does catching the base class change behaviour for the 8
exit_on_errorblocks, which catch one subclass each? (proposed) No. The report and exit code are the same for that subclass. An exception that is not aDevOpsCLIErrorstill propagates as it does today. - refactor(config): the config barrel and the unused config names go, and the package inits stop re-exporting #776 also moves single-consumer constants. Which item moves
CONST_ERROR_CODE_*? (proposed) This one, since the codes become class data rather than constants. refactor(config): the config barrel and the unused config names go, and the package inits stop re-exporting #776 and the constants moves filed from the same review skip that family.
Update 2026-10-08: refinement
OTelTyper has exit_on (#767, core/cli.py:118-120), used by commands/gh.py and commands/release.py; this item makes it the default. Counts: 20 hand-rolled exits, 13 exit_on_error blocks, 103 classes, 44 codes.
-
new_typer()reports everyDevOpsCLIErrorby default; no app passesexit_on=. -
exit_on_erroris only that wrapper's implementation;cli_command_handler, the 20 sites and 13 blocks are deleted.
Sub-issues
Collapse Sub-issuesSub-issues
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsReady
- StatusShow more project fieldsReady
Activity
dan-petty commentedon Oct 8, 2026
Two more hand-rolled exits for the seam, checked at 910b823. Neither is among the 20
typer.Exit(... exc.exit_code)sites counted here, because both exit 1 instead of exc.exit_code:roadmap runcatches RoadmapRunError, prints it and raises typer.Exit(1) (commands/roadmap.py:554-556), and commands/roadmap.py has_exit_on_failure(:101-107, 13 uses), which prints ': ' with safe=True and exits 1. #1365 changes :554-556 to print the RoadmapRunError message with safe=True (the message will name each failed job and its error). It leaves CLI traceback policy to this item.(This item's #983 note is part of the single combined #983 comment in graphql-budget's related_edits.)
dan-petty commentedon Oct 8, 2026
Linked: #1372. The
prapp has noexit_on(commands/pr.py:61-64), so aGitHubOperationErrorescapes as a traceback; this item's default exit path covers it and removes anyexit_on=#1372 adds. Found by the 2026-10-08 backlog review.refactor(config): remove config barrel and unused config names, and s…
fix(config): a config file that is not valid YAML stops the load with…
dan-petty commentedon Oct 28, 2026
This item is too large for one pull request, so it becomes two sub-issues. Each has its own change and pull request.
DevOpsCLIErrorthrough one exit seam, the wrapper inOTelTyper.command, with its exit status and no traceback. It deletesexit_on=, theexit_on_errorblocks in commands and the hand-rolledtyper.Exit(exc.exit_code)sites, and movesconfigontonew_typer().error_codeandexit_code. The forwarding__init__methods, the unused classes and theCONST_ERROR_CODE_*constants go, anddocs/ERRORS.mdkeeps the same codes.Evidence (origin/main 08d70ca, 2026-10-28):
cli_command_handleris already gone. OnlyCHANGELOG.mdnames it.exit_on=, 40exit_on_errorblocks are in 15 command modules, and 21 sites raisetyper.Exit(exc.exit_code)by hand (cloudflare.py9,valkey.py9,sandbox.py,telemetry.py,scan.py).commands/config.pybuilds a plaintyper.Typer.__init__methods that only callsuper().__init__, and 46CONST_ERROR_CODE_*constants.Decisions on the key questions:
OTelTyper.command, whichnew_typer()gives every command. A decorator can be forgotten; the wrapper cannot. An app callback withinvoke_without_command=Truegets the same report.roadmap's_exit_on_failureexits with status 1, not with the error'sexit_code. It stays as it is, because a change to it changes exit statuses. A later item can move it.fix(cli): every command reports a DevOpsCLIError through one exit seam (
refactor(exceptions): each exception class declares its error_code an…
dan-petty commentedon Oct 29, 2026
Both parts of this item are merged:
new_typer()incore/cli.pyreports everyDevOpsCLIErrorthat a command or a command callback raises: one error line, the error's exit status, and no traceback. Theexit_onparameter, theexit_on_errorblocks and the hand-written handlers are deleted.error_codeandexit_codeas class data. The__init__methods that only forwarded, the classes that no code raises, catches or names, and theCONST_ERROR_CODE_*constants are deleted.docs/ERRORS.mdlists the same code and status for each remaining class.