Summary
Three route handlers have a pattern where a bare raise IOError above an except OSError block makes the structured JSON error response unreachable. Clients receive raw 500 stack traces instead of the clean JSON error that PR #90 added.
In Python 3.3+, IOError is an alias for OSError. So this pattern:
except(IOError):
raise IOError
except OSError:
return jsonify({'message': 'A filesystem error occurred.', 'status_code': 'error'}), 500
behaves as follows:
- Any filesystem error raises OSError
- The first clause catches it (because IOError == OSError)
raise IOError raises a new bare exception, losing the original traceback
- A raised exception inside an except clause propagates out it does NOT fall through to the second except
- Flask returns a raw 500 with a stack trace
The second except OSError is dead code. It never runs.
Affected routes:
API/Routes/Case/CaseRoute.py:106-109 /copyCase
API/Routes/Upload/UploadRoute.py:402-405 template deletion
API/Routes/Upload/UploadRoute.py:652-655 batch import
Context: PR #90 added the except OSError: return jsonify(...) handlers specifically to stop leaking stack traces. The commit messages ("preserve existing IOError behavior") suggest the IOError re-raise was left intentionally but that decision makes the new OSError handler unreachable, which contradicts PR #90's stated goal. Clarifying whether this was an oversight or intentional before opening a fix PR.
What did you expect? (optional)
No response
How can we reproduce it?
Trigger a filesystem error in /copyCase e.g., make the data storage directory read-only, then POST to /copyCase with a valid session.
Expected: 500 with JSON {"message": "A filesystem error occurred.", "status_code": "error"}
Actual: 500 with raw HTML stack trace (PermissionError + full traceback)
Static check:
grep -A 2 'except(IOError):$' API/Routes/
Environment (optional)
Branch: main @ 5f8f89a
Python 3.10+ (IOError/OSError alias applies since Python 3.3)
Logs or screenshots (optional)
No response
Related issue, PR, or discussion (optional)
Proposed track
None
Summary
Three route handlers have a pattern where a bare
raise IOErrorabove anexcept OSErrorblock makes the structured JSON error response unreachable. Clients receive raw 500 stack traces instead of the clean JSON error that PR #90 added.In Python 3.3+,
IOErroris an alias forOSError. So this pattern:behaves as follows:
raise IOErrorraises a new bare exception, losing the original tracebackThe second
except OSErroris dead code. It never runs.Affected routes:
API/Routes/Case/CaseRoute.py:106-109/copyCaseAPI/Routes/Upload/UploadRoute.py:402-405template deletionAPI/Routes/Upload/UploadRoute.py:652-655batch importContext: PR #90 added the
except OSError: return jsonify(...)handlers specifically to stop leaking stack traces. The commit messages ("preserve existing IOError behavior") suggest the IOError re-raise was left intentionally but that decision makes the new OSError handler unreachable, which contradicts PR #90's stated goal. Clarifying whether this was an oversight or intentional before opening a fix PR.What did you expect? (optional)
No response
How can we reproduce it?
Trigger a filesystem error in /copyCase e.g., make the data storage directory read-only, then POST to /copyCase with a valid session.
Expected: 500 with JSON {"message": "A filesystem error occurred.", "status_code": "error"}
Actual: 500 with raw HTML stack trace (PermissionError + full traceback)
Static check:
Environment (optional)
Branch: main @ 5f8f89a
Python 3.10+ (IOError/OSError alias applies since Python 3.3)
Logs or screenshots (optional)
No response
Related issue, PR, or discussion (optional)
except OSErrorJSON handlers that are now unreachable - merged)Proposed track
None