errors: AST linter check_error_codes (raise + registry enforcement)#104
Closed
AbdelStark wants to merge 1 commit into
Closed
errors: AST linter check_error_codes (raise + registry enforcement)#104AbdelStark wants to merge 1 commit into
AbdelStark wants to merge 1 commit into
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
4 tasks
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.
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.Without these, the registry from #21 drifts silently the moment anyone starts raising real exceptions.
Solution
tools/lint/check_error_codes.pygeno_lewm/errors.pywithastto discover the legal class set — no runtime import dependency..pyfile under the targets (defaultgeno_lewm/) and inspects everyast.Raise.raiseinsideexcept); flags everything else not in the registry.raise_geno_lewm_errormessage; unknown names getregistered_error_code(likely registry drift).file:line:col: error: [check] message.errors.pyitself (self-reference would loop).tests/lint/test_check_error_codes.py: registry discovery, bare re-raise, Name & Attribute raises, builtin raises (parametrized over 6 common exceptions),raise … from, syntax errors as violations,main()exit codes, format spec..github/workflows/lint-errors.yml: standalone per-PR workflow running the linter. Designed to fold into the full per-PR CI workflow when testing: implement GitHub Actions per-PR CI workflow #86 lands.Validation
Caveats
pull_request/pushtomain. Once testing: implement GitHub Actions per-PR CI workflow #86 ships the full per-PR CI, this can be merged into it.raise GenoLeWMError(...)because the root class is not inERROR_CODES. Intentional — RFC says leaf classes only.tachandflake8-tidy-importsmake: simple, fast, false-positive only on dynamic raises (raise cls(...)whereclsis a runtime variable) — which is itself a smell the spec discourages.Closes #22