Return clear errors instead of crashes on three production failure paths - #277
Merged
Merged
Conversation
- Reject experiment IDs Firestore can't store (e.g. an unfilled "__DATAPIPE_STUDY1_ID__" placeholder) with the normal not-found response. Firestore throws on these instead of missing, so /api/data answered with a 500. - Log the provider error when createexperiment returns a 502, so the failure is visible in Cloud Logging and not only in the browser. - Check the HTTP status in OSF listFiles. An OSF error response crashed with "Cannot read properties of undefined (reading 'filter')", which hid OSF's real status and failed uploads permanently through the collision cache. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
getExperiment() returns null for a missing experiment and for an id Firestore would reject outright, so every endpoint that looks an experiment up by a client-supplied id keeps a single not-found branch and none can reach the doc() call that throws. This replaces the guard copied into six handlers and extends the fix to clear-errors and ensure-derived-paths, which still returned 500s. - api-queue-status checks its `download` queue-entry id the same way (404 instead of a 500 on "__x__" or "a/b"). - writeLog skips ids Firestore would reject, rather than every caller avoiding it on a comment that said it would throw (it never did). - create-experiment logs the Error object and the uid on a 502. - OSF listFiles errors carry OSF's own errors[0].detail, falling back to statusText. - Emulator coverage now includes session start, finalize, clear-errors, ensure-derived-paths and queue-status (experimentID and download). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Three problems found in the first week of production logs (osf-relay, since 2026-09-21).
Reserved experiment IDs returned a 500. On 9/24 a participant site sent the unfilled placeholder
__DATAPIPE_STUDY1_ID__to/api/data3 times. Firestore throws on reserved IDs instead of treating them as a miss. Every endpoint that looks up an experiment from a client-supplied ID now goes throughgetExperiment()(functions/src/experiment-id.ts). It returns null for a missing experiment and for an ID that breaks Firestore's document-ID rules, so each endpoint's existing not-found response covers both:EXPERIMENT_NOT_FOUNDAccess deniedQueue-status also checks its
downloadqueue-entry ID the same way, and returns 404 instead of a 500 for__x__ora/b.writeLogskips IDs Firestore would reject, so it no longer logs an error for each such request.createexperiment 502s left no trace. On 9/23 a user got 4 of these in a row, and Cloud Logging had nothing. The provider, uid and full error (stack and network code, such as ECONNRESET) are now logged. Tokens are not.
OSF
listFilesignored the HTTP status. When OSF returned an error, the code crashed withCannot read properties of undefined (reading 'filter'), which hid OSF's real status. Through collision-cache rehydration, 2 uploads on a legacy OSF experiment failed permanently with only that TypeError to go on.listFilesnow throwsOSF listing failed: <status> <reason>, where the reason is OSF's ownerrors[0].detailor, failing that, the status text. It also guards against a 200 with no file list.Not covered: a made-up but validly formatted experiment ID still creates an ownerless
logs/{id}document through the not-found branch. That predates this PR.Tests
experiment-id-validation.test.js(unit) coversisValidDocumentId.experiment-id-validation-emulator.test.jssends__DATAPIPE_STUDY1_ID__to data, base64, condition and session start (expects 400), and to finalize, clear-errors, ensure-derived-paths and queue-status (expects 403). It also sendsdownload=__x__anddownload=a%2Fbto queue-status for an owned experiment (expects 404).providers-osf.test.jscovers 403/404/410/429 responses, OSF'sdetailin the message, the fallback to status text for a non-JSON body, and a 200 with nodata.🤖 Generated with Claude Code