Skip to content

refactor(exceptions): each exception class declares its error_code and exit_code - #2558

Merged
dan-petty merged 2 commits into
mainfrom
refactor/2490-exception-class-codes
Oct 28, 2026
Merged

dan-petty merged 2 commits into
mainfrom
refactor/2490-exception-class-codes

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

Each exception class now declares its error_code and exit_code as class attributes. Before, the codes were stated three ways: a CONST_ERROR_CODE_* constant, an __init__ default, and a keyword that each subclass passed to its base again. Most __init__ methods of the exception package only repeated their base for that reason.

  • DevOpsCLIError declares error_code = "DEVOPS_CLI_ERROR" and exit_code = 1. Each subclass declares the one that differs from its base, and an instance takes its class's codes.
  • exit_code= stays on the base and on the domain bases that took it, as an override for one instance. SubprocessError, ToolExecutionError, CosignError, CosignVerificationError and the err_type of core/process.py use it for a failed subprocess's own status. error_code= goes, because no raise site set it.
  • 28 __init__ methods go: the 17 that passed their own arguments to their base unchanged with their base's defaults, the 4 whose default message no caller used, and those of the 7 deleted classes. The 74 that stay add detail keys, build the message, or give an argument a default of its own.
  • 7 classes that no module in src raises, catches or names go: ConstellationQuiesceError, ConstellationFailoverError, ConstellationResumeError, GitOpsSyncError, InsecureConfigError, SecretExposureError and InvalidVersionError, with their re-exports and the tests that only built them.
  • The 46 CONST_ERROR_CODE_* constants, the 4 CONST_GITHUB_*_ERROR_CODE constants and the 10 DEFAULT_* attributes go. The tests that read them compare with the code's string.
  • The error catalog generator reads the codes from each class. Its note on the exit status said that only three command groups exit with it; since the one exit seam every command does, and the note says so.
  • docs/ERRORS.md keeps the code, exit status, domain and description of every remaining class, and loses the 7 rows of the deleted classes. CONTRIBUTING.md says how a class declares its codes, and docs/SDLC.md points to it.
  • New tests hold each class's codes equal to its row in docs/ERRORS.md, an error built with no override to its class's codes, and every __init__ to doing more than forwarding to its base.

The source loses a net 495 lines. With the one exit seam, this completes #1006.

Closes #2490

Change: openspec/changes/archive/2026-10-28-2490-exception-class-codes/

…d exit_code

`DevOpsCLIError` declares `error_code` and `exit_code` as class
attributes, and each subclass declares the one that differs from its
base. An instance takes its class's codes. `exit_code=` stays as an
override of one instance, for a failed subprocess's own status;
`error_code=` goes, because no raise site set it.

- 28 `__init__` methods go: the 17 that only passed their own
  arguments to their base, the 4 whose default message no caller used,
  and those of 7 classes that no code raises, catches or names.
- The 46 `CONST_ERROR_CODE_*` constants, the 4
  `CONST_GITHUB_*_ERROR_CODE` constants and the 10 `DEFAULT_*`
  attributes go. Tests compare with the code's string.
- The error catalog generator reads the codes from each class. Its note
  on the exit status now says that every command exits with it, as it
  does since the one exit seam.
- `docs/ERRORS.md` keeps every remaining code and exit status.
  `CONTRIBUTING.md` says how a class declares its codes.
@dan-petty

Copy link
Copy Markdown
Owner Author

Test evidence:

  • uv run devops ci fail-to-pass --base origin/main: 5 tests fail on the base and pass on the branch: test_each_error_class_declares_the_codes_of_its_catalog_row, test_an_error_built_without_an_override_carries_its_class_codes, test_one_error_code_maps_to_one_exit_status (it now reads the class attributes), test_base_devops_cli_error and test_configuration_and_error_catalog_docs_describe_real_surface. 756 tests in the 14 changed test files pass on both.
  • test_no_error_class_has_an_init_that_only_forwards_to_its_base passes on the base too: there each subclass gave its error_code argument a different default, so no __init__ matched. It holds the forwarding __init__ methods out from now on.
  • Full uv run devops ci test on the branch: 12,209 passed. Two failures came from that run, and both are fixed in the pushed commit: the catalog test also saw DevOpsCLIError subclasses that other tests define, so it now takes only devops_cli modules; and it read docs/ERRORS.md through its own file, which tests.support.paths.REPO_ROOT now replaces. After the fix, tests/test_exceptions.py, tests/test_test_module_independence.py, tests/test_docs.py and tests/test_pr_cmd.py pass together (117). The run's workspace tripwire named CONTRIBUTING.md and docs/SDLC.md, which I edited while it ran.
  • uv run mypy on the 24 changed source files: no issues. uv run devops docs check: up to date.
  • git diff origin/main -- docs/ERRORS.md: 7 rows removed (the deleted classes) and the note on the exit status changed; no other row changed.

Pending a person: review the diff in tuicr (tuicr -r origin/main..HEAD).

@dan-petty
dan-petty marked this pull request as ready for review October 28, 2026 23:00
@dan-petty
dan-petty merged commit 410dece into main Oct 28, 2026
17 checks passed
@dan-petty
dan-petty deleted the refactor/2490-exception-class-codes branch October 28, 2026 23:19
dan-petty pushed a commit that referenced this pull request Oct 29, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.12.0](v0.11.3...v0.12.0)
(2026-10-29)


### Features

* **ai:** constrain structured replies on the openai and claude
providers ([#2550](#2550))
([4f7390a](4f7390a))
* **argo:** retire the Helm release records of the charts that Argo CD
renders ([#2568](#2568))
([cabfcd4](cabfcd4))
* **k8s:** devops k8s tunnel keeps the cloudflared forward to
k8s.<domain> running
([#2567](#2567))
([f9493fa](f9493fa)),
closes [#1641](#1641)
* **monitoring:** alert when the otel collector fails to export spans,
metric points or log records
([#2565](#2565))
([4fc8ff7](4fc8ff7))
* **telemetry:** the roadmap Service counts its GitHub writes, budget
holds, Firecrawl searches and own deliveries, and caps refine's comments
on one item
([#2556](#2556))
([9819877](9819877)),
closes [#2475](#2475)


### Bug Fixes

* **git:** report a worktree that a run in parallel removed as removed,
not a failed reclaim
([#2557](#2557))
([a556984](a556984)),
closes [#2408](#2408)
* **k8s:** the devops perimeter opens only the collector's OTLP/HTTP
port, 4318
([#2549](#2549))
([d156ce7](d156ce7))
* **sandbox:** devops sandbox logs reads each line with its stream from
a real engine
([#2546](#2546))
([e7216d5](e7216d5)),
closes [#2520](#2520)
* **service:** the webhook route refuses an unsigned or oversized
delivery before it reads the body, and a rate limit guards it
([#2553](#2553))
([40efcd4](40efcd4)),
closes [#2476](#2476)


### Performance Improvements

* **ai:** price a request with one load of the settings
([#2555](#2555))
([5d86538](5d86538)),
closes [#1420](#1420)


### Code Refactoring

* **config:** a default that backs a settings field is read only through
the settings
([#2561](#2561))
([0702d13](0702d13))
* **exceptions:** each exception class declares its error_code and
exit_code ([#2558](#2558))
([410dece](410dece))
* **review:** render the review report from one input, outside the
orchestrator
([#2563](#2563))
([9e73e6d](9e73e6d)),
closes [#1008](#1008)
* **security:** src has no unreviewed Bandit findings, and the gate
scans src at low severity
([#2560](#2560))
([45261dd](45261dd)),
closes [#1538](#1538)
* **security:** the scanners stop looking for mocks, and their tests run
on the scanner fake
([#2551](#2551))
([2b7f37a](2b7f37a))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.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

1 participant