errors: AST linter check_error_codes (raise + registry enforcement)#105
Merged
Conversation
Adds tools/lint/check_error_codes.py implementing the two AST checks required by RFC-0012 §3.3 and RFC-0015 §3.4: - raise_geno_lewm_error: every ``raise X(...)`` in geno_lewm/ raises a registered GenoLeWMError subclass (or is a bare re-raise). - registered_error_code: the raised class is one of the leaf classes listed in geno_lewm/errors.py::ERROR_CODES. The linter parses geno_lewm/errors.py with the ast module to discover the legal class set, so it has no runtime dependency on the package being installable. Output is GitHub-Actions-friendly file:line:col: error: [check_name] message. Wired into a standalone .github/workflows/lint-errors.yml that runs on PR. Will fold into the full per-PR CI workflow (#86) when that lands. Tests in tests/lint/test_check_error_codes.py cover: - registry discovery against the real errors module - bare re-raise (allowed) - registered raises (Name and Attribute forms) - builtin raises (flagged) - unregistered class raises (flagged) - raise-from (still inspects class) - syntax errors (reported as violations) - the errors module itself is skipped Closes #22
This was referenced May 20, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Re-opening with base=main since the original PR (#104) was closed when its base branch was deleted on merge of #103.
Problem
RFC-0012 §3.3 and RFC-0015 §3.4 require two AST checks at PR time:
raise_geno_lewm_error—raise X(...)ingeno_lewm/only raisesGenoLeWMErrorsubclasses.registered_error_code— the raised class is one of the leaves listed inERROR_CODES.Solution
tools/lint/check_error_codes.py— parsesgeno_lewm/errors.pywithastto derive the legal class set (no runtime import dependency); walks targets; flags non-registered raises with GitHub-Actions-friendly diagnostics.tests/lint/test_check_error_codes.py— 19 cases covering bare re-raise, Name/Attribute raises, builtin raises (parametrized over 6),raise … from, syntax errors, and the self-skip onerrors.py..github/workflows/lint-errors.yml— standalone per-PR workflow; designed to fold into testing: implement GitHub Actions per-PR CI workflow #86's full CI when that lands.Validation
Caveats
raise GenoLeWMError(...)because the root class is not inERROR_CODES. Intentional — RFC says leaf classes only.raise cls(...)).Closes #22