Skip to content

refactor(exceptions): let validators raise own errors and bound details once #1877

Open

Description

@dan-petty

Friction

AGENTS.md line 192 says bare ValueError, RuntimeError and TypeError are "strictly prohibited" in domain logic. But Pydantic v2 validators must raise ValueError. The rule produced a taxonomy of 110 classes. Fifteen of them inherit a builtin only to satisfy the rule. It also produced a hand-written list of nine modules to enforce the rule. The project applies the bound on detail length at each call site, so 153 hand-written [:256] slices exist.

Evidence

  • raise ValueError(...), RuntimeError or TypeError appear 120 times in src/ (109, 5 and 6). Twenty-three of them are inside validators (count of the verification pass).
  • The enforcing test (test_architectural_invariants.py:244-276) checks nine modules that it names inside the function. Every other module passes because the test does not list it.
  • docs/SDLC.md:130 allows dual inheritance as an escape. TESTING.md:110 requires test builders to raise TypeError.
  • A prototype ast-grep rule for the three raises outside a function decorated @*validator reports 97 findings on src/ today (verification pass, not repeated).
  • DevOpsCLIError already masks secrets in exceptions/base.py. 153 sites slice [:256] and 38 sites slice [:CONST_MAX_ERROR_DETAIL_LENGTH].

Decision (owner, 2026-10-22)

Pydantic validators and library callbacks raise the exceptions their framework expects. One CLI boundary maps any other exception to an exit code and an error code. DevOpsCLIError bounds details once, in its constructor.

Proposed remedy

  • Apply pairs A18 and A19, O03 and O11. Write the pasted text in ASD-STE100 Simplified Technical English.
  • Move the 256-character bound into DevOpsCLIError.__init__. Delete the per-site slices in a follow-up pull request.
  • Look for a CLI-boundary handler that maps a non-DevOpsCLIError exception to an exit code and an error code. Add one if none exists.
  • Replace the nine-module test with an ast-grep rule over all of src/. The rule matches the three raises outside validators. Convert the 97 sites first, or give them a taxonomy class. Do not ship the rule at warning severity.

What it deletes

  • 33 lines of test and the list of nine modules.
  • The 191 per-site slices (follow-up pull request).

Tests

  • A rule test (ast-grep test) with a passing and a failing case, including a validator.
  • A test that the base class bounds a message of more than 256 characters in details.
  • The existing tests that assert subclass codes for originated errors stay.

Dependencies

  • docs(agents): agents and devops ai write in ASD-STE100 Simplified Technical English. Both items edit AGENTS.md.

Acceptance criteria

  • The rule runs on all of src/ and reports 0 findings.
  • No call site truncates details by hand.
  • uv run devops ci passes.

Size: M.

Proposed design

Problem statement

The project prohibits bare ValueError, RuntimeError, and TypeError in domain logic. But Pydantic v2 validators must raise ValueError. This rule created 110 exception classes and 153 hand-written detail slices. The fix lets validators raise framework-expected exceptions. A single CLI boundary maps other exceptions to exit codes. DevOpsCLIError bounds details once in its constructor.

Acceptance criteria

  • Criterion 1: The ast-grep rule runs on all of src/ and reports 0 findings.
    Verification: Run ast-grep scan --rule src/ and confirm the output reports 0 findings.
  • Criterion 2: DevOpsCLIError.init truncates details to at most 256 characters.
    Verification: Run a test that constructs DevOpsCLIError with a details string longer than 256 characters and asserts the stored value is at most 256 characters.
  • Criterion 3: A CLI-boundary handler maps a non-DevOpsCLIError exception to an exit code and an error code.
    Verification: Run a test that raises a ValueError through the CLI entry point and assert the process exits with a non-zero code and prints an error code.
  • Criterion 4: The nine-module test in test_architectural_invariants.py is removed.
    Verification: Confirm test_architectural_invariants.py no longer contains the list of nine module names.
  • Criterion 5: The ast-grep rule test includes a passing case (a validator) and a failing case (a non-validator raise).
    Verification: Run ast-grep test and confirm both the passing and failing cases are reported correctly.
  • Criterion 6: uv run devops ci passes.
    Verification: Run uv run devops ci and confirm all checks pass.

Key questions

  • What exception behavior do validators and library callbacks use, and how does the CLI boundary handle other exceptions?: Pydantic validators and library callbacks raise the exceptions their framework expects. One CLI boundary maps any other exception to an exit code and an error code. DevOpsCLIError bounds details once, in its constructor. (proposed)
  • Does a CLI-boundary handler that maps a non-DevOpsCLIError exception to an exit code and an error code already exist?: Unknown. The remedy says to look for one and add it if none exists. (proposed)
  • What are pairs A18 and A19, O03 and O11?: Not established in the available context. These appear to be internal rule or taxonomy pair identifiers referenced by the issue author. (proposed)
  • Does docs/SDLC.md allow dual inheritance as an escape from the bare-builtin prohibition?: Yes. docs/SDLC.md:126 states that idiomatic multiple inheritance is permitted to preserve standard exception catches. [sources: docs/SDLC.md:126]
  • Does CONTRIBUTING.md prohibit bare built-in exceptions?: Yes. CONTRIBUTING.md:25 states that raising bare Python built-in exceptions (ValueError, RuntimeError, TypeError) is strictly prohibited. [sources: CONTRIBUTING.md:25]

Fit

Needs splitting into 1 items:

  1. Delete the 191 per-site [:256] and [:CONST_MAX_ERROR_DETAIL_LENGTH] slices now that DevOpsCLIError.init bounds details.

Suspected block

None.

Dependencies

None.

Alternatives check of 2026-11-01: not-applicable.
Tool: none found.

Activity

  1. added
    source/agent
    type/refactor
    on Oct 22, 2026
  2. dan-petty commented on Oct 22, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: at intake only a critical fix goes into a release; a release start pulls Ready items in, P0 features first.

    • Type: type/refactor. The candidate focuses on refactoring exception handling and CLI boundary logic, which fits the refactor type.
    • Priority: P2-Medium. It improves code quality and maintainability but does not address a critical issue or bug.
    • Value: Medium. The changes improve code clarity and reduce redundancy, benefiting developers and future maintainers.
    • Effort: High. The refactor involves multiple components including exception handling, CLI boundary logic, and test updates, requiring significant coordination and testing.
  3. dan-petty commented on Oct 28, 2026

    @dan-petty
    OwnerAuthor

    The proposal at 4da1e34 needs splitting into 1 items. A person splits the item into the items below, or replies in a comment or edits the body to keep one item, and the next refine round looks at the item again.

    1. Delete the 191 per-site [:256] and [:CONST_MAX_ERROR_DETAIL_LENGTH] slices now that DevOpsCLIError.init bounds details.
  4. added
    priority/p2-medium
    status/new
    value/medium
    effort/high
    on Oct 28, 2026
  5. devops-cli-service commented on Nov 1, 2026

    @devops-cli-service
    Contributor

    Alternatives check: not-applicable

    Tool: none found

    Checked on 2026-11-01. A person decides what this means for the item. The check changes no label and closes no issue.

  6. changed the title [-]refactor(exceptions): validators and library calls raise their own exceptions, the CLI boundary maps them and DevOpsCLIError bounds details once[/-] [+]refactor(exceptions): let validators raise own errors and bound details once[/+] on Nov 6, 2026
  7. dan-petty commented on Nov 6, 2026

    @dan-petty
    OwnerAuthor

    The job shortened the title of this item. The summary had 122 characters, and the limit is 60. The type and the scope stay.

    • Before: refactor(exceptions): validators and library calls raise their own exceptions, the CLI boundary maps them and DevOpsCLIError bounds details once
    • After: refactor(exceptions): let validators raise own errors and bound details once
    • Source of the summary: the background model
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

    effort/highpriority/p2-mediumsource/agentstatus/newtype/refactorvalue/medium

    Type

    No type

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions