Skip to content

feat: drop legacy raw-X12 fallback; require pyx12 codes (PR 5 of 6)#179

Merged
azoner merged 1 commit into
masterfrom
feat/error-codes-tighten-pr5
May 6, 2026
Merged

feat: drop legacy raw-X12 fallback; require pyx12 codes (PR 5 of 6)#179
azoner merged 1 commit into
masterfrom
feat/error-codes-tighten-pr5

Conversation

@azoner

@azoner azoner commented May 6, 2026

Copy link
Copy Markdown
Owner

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.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.
  • Removed the module-level seg_errors / ele_errors tuples (unused).
  • Kept isa_errors and ISAError.__post_init__ — ISA-level codes are TA1 codes, not migrated to pyx12 codes (out of scope per the plan).

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.

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\", 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_rejected on both SegError and EleError.

Test plan

  • pytest pyx12/test/: 581 passed (579 baseline + 2 new "legacy rejected" tests)
  • mypy --strict pyx12: clean (88 files)
  • ruff check + format --check: clean

Behavior change

This PR is the breaking-change gate for the refactor. Any external consumer constructing SegError / EleError directly with raw X12 codes will now hit EngineError at 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

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>
@azoner azoner merged commit f0cbed4 into master May 6, 2026
16 checks passed
@azoner azoner deleted the feat/error-codes-tighten-pr5 branch May 6, 2026 04:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant