Skip to content

fix: preserve original exception type in FileClass write methods#411

Open
Anirudh77715 wants to merge 2 commits intoEAPD-DRB:mainfrom
Anirudh77715:feature/353-fix-fileclass-exceptions
Open

fix: preserve original exception type in FileClass write methods#411
Anirudh77715 wants to merge 2 commits intoEAPD-DRB:mainfrom
Anirudh77715:feature/353-fix-fileclass-exceptions

Conversation

@Anirudh77715
Copy link
Copy Markdown

@Anirudh77715 Anirudh77715 commented Apr 2, 2026

This fixes an issue where IOError exceptions were swallowed and incorrectly re-raised as IndexError in writeFile and writeFileUJson.

Linked issue

Existing related work reviewed

Overlap assessment

  • Classification: none
  • Overlapping items: none
  • Why this is not duplicate/superseded: no other PR touches FileClass.py exception handling

Why this PR should proceed

Both writeFile() and writeFileUJson() catch (IOError, IndexError) but unconditionally re-raise as IndexError, masking the original exception type. When an IOError occurs during file write, callers see IndexError instead — making debugging misleading. Using bare raise preserves the original exception type and traceback.

Summary

  • What changed: Replaced raise IndexError with bare raise in both writeFile() and writeFileUJson() in API/Classes/Base/FileClass.py
  • Why: The original code masks IOError as IndexError, making debugging misleading; bare raise preserves the correct exception type

Validation

  • Tests added/updated (or not applicable)
  • Validation steps documented
  • Evidence attached (logs/screenshots/output as relevant)

Documentation

  • Docs updated in this PR (or not applicable)
  • Any setup/workflow changes reflected in repo docs

Scope check

  • No unrelated refactors
  • Implemented from a feature branch
  • Change is deliverable without upstream OSeMOSYS/MUIO dependency
  • Base repo/branch is EAPD-DRB/MUIOGO:main (not upstream)

Exception rationale

This fixes an issue where IOError were swallowed and incorrectly re-raised as IndexError in writeFile and writeFileUJson. Closes EAPD-DRB#353
@github-actions github-actions bot added needs-intake-fix PR intake structure needs maintainer follow-up and removed needs-intake-fix PR intake structure needs maintainer follow-up labels Apr 2, 2026
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.

[Bug] FileClass.py writeFile() swallows IOError and re-raises it as IndexError — misleading exception type masks real I/O failures

1 participant