fix: narrow broad exception handlers to prevent silent error swallowing - #216
fix: narrow broad exception handlers to prevent silent error swallowing#216RohithPariki wants to merge 1 commit into
Conversation
|
Thanks for working on this. Most of the file/JSON cleanup changes look reasonable, but the two changes in Those Could you please preserve the fallback for optimizer-call failures while making it observable—for example, keep a broad catch at this boundary and emit a sanitized warning, or introduce/catch a shared backend exception type plus the parsing exceptions? Please also add regression tests for a backend/runtime failure and malformed model output, asserting that the fallback is returned. The narrower cleanup/parser-only catches elsewhere can remain. A full test-suite and Ruff run would also be helpful. |
Fixes #215
Summary of Changes
Replaced generic
except Exception:blocks with targeted exception types (OSError,ValueError,TypeError,json.JSONDecodeError,KeyError,AttributeError) across core components:skillopt/engine/trainer.py: Catch targeted JSON/IO/attribute errors when reading patch files.skillopt/envs/spreadsheetbench/adapter.py&rollout.py: Replace broad exception handlers with specific JSON/KeyError/TypeError handling during cached results loading.skillopt/gradient/aggregate.py: Replace broadexcept Exception:with targeted exceptions when parsing LLM merge responses.skillopt_sleep/backend.py: Narrow exception scope across 12 locations (file removal, CLI output parsing, JSONL decoding) so unexpected system/programming bugs are not silently swallowed.Verification
pytest: 146 core engine tests passed cleanly.