Skip to content

refactor(tilib): narrow ti_ar fixture except to TilibParamError (#218) - #220

Merged
k-yoshimi merged 3 commits into
developfrom
feat/ti-except-narrowing-218
Jun 8, 2026
Merged

refactor(tilib): narrow ti_ar fixture except to TilibParamError (#218)#220
k-yoshimi merged 3 commits into
developfrom
feat/ti-except-narrowing-218

Conversation

@k-yoshimi

@k-yoshimi k-yoshimi commented Jun 7, 2026

Copy link
Copy Markdown
Owner

Summary

Narrows the broad except Exception: in ti_ar_params.py to the specific TilibParamError (ierr=1, TI_ERR_INVALID) that the ti C ABI raises when a parameter name is unregistered. Other exception classes — TilibStateError (ierr=2), TilibRunError (ierr=3), TilibNotImplementedError (ierr=4) — now propagate normally instead of being silently swallowed.

Closes #218 (in part — see "Deferred" below).

Why

Codex pre-push review on PR #219 flagged that the except Exception: pattern in the ti fixtures could mask real bugs (bad value type, library-state errors, calculation failures) — only registry-rejection (ierr=1) was meant to be silenced for UNREGISTERED_KEYS. This PR addresses the precedent file on develop; the same fix in ti_w_params.py (added in PR #219) is deferred.

Scope

  • Modified: python/tilib/tests/fixtures/ti_ar_params.py (4 except sites narrowed, import added, comment clarified)
  • Verified narrowing chain against:
    • ti/ti_api.h:27 (TI_ERR_INVALID = 1)
    • ti/ti_param_registry.f90:45-47, 90-91, 190-191 (registry returns ierr=1 for unknown name and bad value)
    • python/tilib/errors.py:46-51 (_CODE_MAP[1] = TilibParamError)

Deferred

python/tilib/tests/fixtures/ti_w_params.py has the same except Exception: pattern but only exists on PR #219's branch (feat/fixture-parity-215). Applying the same narrowing to ti_w_params.py is deferred to a small follow-up commit after #219 merges, so this PR's diff stays clean against develop. #218 will be re-resolved (or kept open with a tracking note) after that follow-up lands.

ti_min_params.py has no try/except — no work needed there.

Test plan

  • Local: PYTHONPATH=python pytest python/tilib/tests/ --timeout=120 -q → 43 passed, 2 skipped (no regression)
  • CI: python-tests.yml job passes
  • Bugbot COMPLETED

Pre-push gate

  • ✅ Local pytest: 43/2 (clean)
  • ✅ In-house code review (feature-dev:code-reviewer): READY-TO-PUSH, no HIGH/MED
  • ✅ Codex independent review (codex:codex-rescue): READY-TO-PUSH, no HIGH/MED
  • ✅ REVIEW_OK marker placed for HEAD 6ca586f7

🤖 Generated with Claude Code


Note

Low Risk
Test-fixture-only change; behavior unchanged for expected invalid names, but real non-param errors will now fail tests loudly instead of being masked.

Overview
Replaces broad except Exception: handlers in ti_ar_params.py with except TilibParamError, so only registry/invalid-parameter failures (C ABI ierr=1) are silenced for UNREGISTERED_KEYS. TilibStateError, TilibRunError, and TilibNotImplementedError now surface instead of being swallowed during scalar, 1D array, and 2D matrix set_param calls.

Adds from tilib.errors import TilibParamError and tightens inline comments at all four catch sites. Same pattern for ti_w_params.py is explicitly deferred to a follow-up after PR #219.

Reviewed by Cursor Bugbot for commit 6ca586f. Bugbot is set up for automated code reviews on this repo. Configure here.

k-yoshimi and others added 3 commits June 1, 2026 19:59
Spec for backfilling missing python/<mod>/tests/fixtures/<case>_params.py
so the Linux-canonical equivalence suite covers the full committed
baseline corpus, not just a hand-picked subset.

Scope locked across 3 Codex review passes:
- 4 new fixtures: fp_jt60, ti_w, tr_m0904, wrx_jt60
- Rename ti_iter01_params.py -> ti_min_params.py (5 importers)
- Register wrx_jt60 in test_run/test_definitions.conf
- eq_jt60 deferred to follow-up issue (eqjt60.gs never committed)

Builds on the Linux-canonical equiv policy (PR #216, 2026-05-26 spec).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…rror (#218)

The fixture's _apply_array and apply functions used `except Exception:` to
silence registry-rejection errors for UNREGISTERED_KEYS. Codex pre-push
review on PR #219 flagged that this would also mask real bugs (bad value
type, index OOB, registry returning a different ierr code).

ti's C ABI raises specific subclasses (python/tilib/errors.py):
- TilibParamError (ierr=1, "invalid parameter name or value")
- TilibStateError (ierr=2)
- TilibRunError (ierr=3)
- TilibNotImplementedError (ierr=4)

Registry-rejection of an unregistered name is exactly ierr=1
(TI_ERR_INVALID per ti/ti_api.h). Narrowing the except to TilibParamError
preserves the silence-for-unregistered behavior while letting real bugs
(state, run, type errors) propagate normally.

All 4 except sites in ti_ar_params.py narrowed:
- _apply_array dict branch (L75)
- _apply_array list branch (L82)
- apply SCALARS loop (L92)
- apply MATRIX_ARRAYS loop (L102)

Local test: 43 passed, 2 skipped (no regression).

The same pattern applies to ti_w_params.py which is added by PR #219.
That fix is deferred to a follow-up commit (or a quick PR) after #219
merges, so this PR's diff stays clean against develop.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Codex pre-push review noted that ierr=1 (TI_ERR_INVALID) covers both
"invalid name" AND "invalid value" per ti/ti_api.h:27; the original
"unknown name" wording was technically accurate only for the
UNREGISTERED_KEYS path. Update comment to reflect both semantics
while documenting the intent.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@k-yoshimi

Copy link
Copy Markdown
Owner Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 6ca586f. Configure here.

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