feat: drop legacy raw-X12 fallback; require pyx12 codes (PR 5 of 6)#179
Merged
Conversation
Fifth slice of the X12 error code generalization plan. Now that every producer in the codebase emits pyx12 codes (PRs #175-#178), the legacy raw-X12 fallback paths in the visitors and the validation tuples in error_item.py are dead. This PR removes them and tightens EleError/SegError __post_init__ to require ERROR_CODES keys. Visitor changes: - pyx12/error_999.py visit_seg / visit_ele: drop the valid_IK3_codes / valid_IK4_codes tuples and the elif fallback. Visitors now only do ERROR_CODES.get(err_cde) — None spec or None ik_code = drop. - pyx12/error_997.py visit_seg / visit_ele: same shape, drop valid_AK3_codes / valid_AK4_codes tuples. Validation tightening (pyx12/error_item.py): - EleError.__post_init__: was `if err_cde not in ele_errors and err_cde not in ERROR_CODES: raise`. Now `if err_cde not in ERROR_CODES: raise`. Error message updated to point to pyx12.error_codes.ERROR_CODES. - SegError.__post_init__: same shape change. - The legacy seg_errors / ele_errors module-level tuples are removed. isa_errors stays (still used by ISAError validation; ISA-level codes are TA1 codes, not in scope of this refactor). x12_code_for in error_codes.py keeps its permissive behavior of falling through to err_cde for unknown codes — needed by the JSON visitor for ISA/GS/ST envelope-level codes ("025", "010", etc.) which aren't migrated to pyx12 codes (out of scope per the plan). Test updates (test_error_item.py): - All SegError/EleError construction tests migrated to pyx12 codes: "1" -> "SEG_1_segment_not_found", "8" -> "SEG_8_trailing_terminators", "1" -> "ELE_1_mandatory_missing", "10" -> "ELE_10_not_used", etc. - Two new tests assert that legacy raw-X12 codes are now rejected: test_invalid_code_legacy_raw_X12_rejected on both SegError and EleError. Verification: - pytest pyx12/test/: 581 passed (579 + 2 new "legacy rejected" tests) - mypy --strict pyx12: clean (88 files) - ruff check + format --check: clean Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.
Fifth slice of the X12 error code generalization plan. Now that every producer in the codebase emits pyx12 codes (#175-#178), the legacy raw-X12 fallback paths in the visitors and the validation tuples in
error_item.pyare dead. This PR removes them and tightensEleError/SegError__post_init__to require ERROR_CODES keys.Visitor changes
pyx12/error_999.pyvisit_seg/visit_ele: drop thevalid_IK3_codes/valid_IK4_codestuples and theeliffallback. Visitors now only doERROR_CODES.get(err_cde)—Nonespec orNoneik_code= drop.pyx12/error_997.pyvisit_seg/visit_ele: same shape, dropvalid_AK3_codes/valid_AK4_codestuples.Validation tightening
pyx12/error_item.py:EleError.__post_init__: wasif err_cde not in ele_errors and err_cde not in ERROR_CODES: raise. Nowif err_cde not in ERROR_CODES: raise. Error message updated to point topyx12.error_codes.ERROR_CODES.SegError.__post_init__: same shape change.seg_errors/ele_errorstuples (unused).isa_errorsandISAError.__post_init__— ISA-level codes are TA1 codes, not migrated to pyx12 codes (out of scope per the plan).x12_code_forinerror_codes.pykeeps its permissive behavior of falling through toerr_cdefor unknown codes — needed by the JSON visitor for ISA/GS/ST envelope-level codes (\"025\",\"010\", etc.) which aren't migrated to pyx12 codes.Test updates (test_error_item.py)
All
SegError/EleErrorconstruction tests migrated to pyx12 codes:\"1\"→\"SEG_1_segment_not_found\",\"8\"→\"SEG_8_trailing_terminators\", etc.\"1\"→\"ELE_1_mandatory_missing\",\"10\"→\"ELE_10_not_used\", etc.Two new tests assert that legacy raw-X12 codes are now rejected:
test_invalid_code_legacy_raw_X12_rejectedon bothSegErrorandEleError.Test plan
Behavior change
This PR is the breaking-change gate for the refactor. Any external consumer constructing
SegError/EleErrordirectly with raw X12 codes will now hitEngineErrorat construction time. Tag for 4.1.0.The X12 ack output (997 / 999) and JSON output remain unchanged — the table-driven visitor lookup produces the same X12 codes as before.
Plan reference
~/.claude/plans/radiant-petting-steele.md— see PR 5 section.🤖 Generated with Claude Code