Fix/449 dead code exception handlers#450
Conversation
…RB#449) Remove 'except(IOError): raise IOError' blocks from three route endpoints. Since IOError is an alias for OSError in Python 3.3+, the raise inside the first except propagated out and made the subsequent 'except OSError' JSON error handlers unreachable dead code. Clients received raw 500 stack traces instead of structured JSON error responses. Affected endpoints: - /copyCase (CaseRoute.py) - uploadCaseUnchunked_old (UploadRoute.py) - uploadXls (UploadRoute.py) Closes EAPD-DRB#449
3213a1e to
8fd48eb
Compare
|
Hey, good find on the dead code! |
|
@Cypher-CP0 Replacing it with except OSError would still risk duplicating or shadowing the existing handler, so removal was the cleanest minimal fix. |
Linked issue
Existing related work reviewed
except OSErrorJSON handlers that are now unreachable (merged)Overlap assessment
except OSErrorJSON handlers this PR makes reachableexcept(IOError): raise IOErrorblocks left above them. This PR completes fix: replace bare raise OSError with structured JSON 500 responses #90's stated goal.Why this PR should proceed
except(IOError): raise IOErrorpattern left above the new handlers makes them unreachable. Clients currently receive raw HTML 500 stack traces, leaking internal details. This is a minimal 6-line deletion that fixes the bug without changing any other behavior.Summary
except(IOError): raise IOErrorblocks from 3 route endpoints:API/Routes/Case/CaseRoute.py-/copyCase(lines 106–107)API/Routes/Upload/UploadRoute.py-uploadCaseUnchunked_old(lines 402–403)API/Routes/Upload/UploadRoute.py-uploadXls(lines 652–653)IOErroris an alias forOSError. The patternexcept(IOError): raise IOErrorcatches any filesystem error (sinceIOError == OSError), then re-raises it. A raised exception inside anexceptclause propagates out - it does not fall through to the nextexcept. This made theexcept OSError: return jsonify(...)handlers added by PR fix: replace bare raise OSError with structured JSON 500 responses #90 completely unreachable.Validation
grep -n "except(IOError):" API/Routes/Case/CaseRoute.py API/Routes/Upload/UploadRoute.py- confirms noraise IOErrorpatterns remainPOST /copyCasewith a valid session → should return{"message": "A filesystem error occurred.", "status_code": "error"}with HTTP 500 instead of a raw stack traceDocumentation
Scope check
fix/449-dead-code-exception-handlers)OSeMOSYS/MUIOdependencyEAPD-DRB/MUIOGO:main(not upstream)Exception rationale