fix(send): stop POST /api/uploads/report crashing on an unknown id - #1165
Merged
Conversation
reportSuspiciousFile -> getUploadParts throws UPLOAD_NOT_FOUND for an id with no upload row. The route had no async error boundary, so the rejection was unhandled and terminated the process — a single request with a random uuid could take down a replica. Wrap the handler in wrapAsyncHandler and tag it with a REPORT_FAILED (404) error via addErrorHandling, matching the sibling upload routes, so an unknown id is answered 404 instead of crashing. Adds a regression test covering the known-id (200) and unknown-id (404) paths. Refs private-issue-tracking#49
radishmouse
approved these changes
Aug 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed?
POST /api/uploads/reportno longer crashes the backend process on an unknown upload id.reportSuspiciousFile→getUploadParts(models/uploads.ts:112) throwsUPLOAD_NOT_FOUNDfor an id with no upload row. The route had no async error boundary (wrapAsyncHandler, try/catch), so the rejection was unhandled and terminated Node — a singlePOST /api/uploads/reportwith a random uuid could take down a replica. Sustained requests give sustained outage.The fix follows the pattern the sibling upload routes already use: tag the route with
addErrorHandling(UPLOAD_ERRORS.REPORT_FAILED)(a new 404) and wrap the handler inwrapAsyncHandler, so the throw routes to the global error handler and answers 404 instead of crashing.Changes
errors/routes.ts— addUPLOAD_ERRORS.REPORT_FAILED(statusCode: 404, "Could not report upload.").routes/uploads.ts— wrapPOST /reportinaddErrorHandling(...)+wrapAsyncHandler(...), with a comment naming the crash it closes.test/routes/uploads.report.routes.test.ts— regression test: known id → 200; unknown id → 404 (andreportUploadis not called). The suite mounts the globalerrorHandlerin its 4-arg error-middleware form so the async boundary is exercised end to end.Verification
src/test/routes/suite green (34 tests).prettier --checkclean on all three files.Why?
thunderbird/private-issue-tracking#49. Same crash class as #43/#45: an unhandled synchronous/async throw in an unguarded handler terminates the process. The fix is to make an unknown id non-fatal — it holds whether or not the caller is authenticated. (The route being reachable without auth is noted separately in #49 as its own concern; this PR is scoped to the crash.)AI disclosure. Written with Claude Code. I set the approach and scope; the agent traced the throw path, made the change, and added the regression test. I reviewed it.
Applicable Issues
thunderbird/private-issue-tracking#49