Skip to content

Comments

fix: preserve exception context and return structured error responses#36

Closed
arnchlmcodes wants to merge 1 commit intoOSeMOSYS:masterfrom
arnchlmcodes:fix-exception-reraise
Closed

fix: preserve exception context and return structured error responses#36
arnchlmcodes wants to merge 1 commit intoOSeMOSYS:masterfrom
arnchlmcodes:fix-exception-reraise

Conversation

@arnchlmcodes
Copy link

Fix: Preserve exception context and return consistent API error responses

This PR fixes incorrect exception re-raising in several routes where raise IOError / raise OSError was used inside except blocks.

Using raise IOError creates a new empty exception, which discards the original error message and traceback. As a result, when failures occur the API returns a generic 500 error with little or no debugging information.


Problem

The previous pattern:

except IOError:
    raise IOError

replaces the original exception instead of propagating it. This removes important context such as the file path, system error message, and traceback, making debugging difficult and producing unclear API responses.


Changes

  • Replaced incorrect exception re-raises with structured error handling:
except IOError as e:
    return jsonify({
        "error": str(e),
        "type": type(e).__name__
    }), 500
  • Applied consistently across affected locations in:
    • CaseRoute.py
    • UploadRoute.py

Result

  • Original exception details are preserved
  • API responses now contain meaningful error information
  • Debugging server-side failures becomes significantly easier
  • Prevents silent loss of exception context

@arnchlmcodes arnchlmcodes deleted the fix-exception-reraise branch February 21, 2026 20:37
@arnchlmcodes arnchlmcodes restored the fix-exception-reraise branch February 21, 2026 20:37
@arnchlmcodes
Copy link
Author

Closed as #33 adrdesses this

@arnchlmcodes arnchlmcodes deleted the fix-exception-reraise branch February 21, 2026 20:43
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