Skip to content

Commit 5bb4c37

Browse files
fix(files): surface a failed upload read-back as the real error
getWorkspaceFile swallows a query failure and returns null unless throwOnError is set, so a transient blip on the post-upload read reported as 'file could not be read back'. Distinguish the two: a real null after a just-committed write is an invariant break, a query failure is itself.
1 parent 3d8e489 commit 5bb4c37

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

apps/sim/app/api/v2/files/route.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,15 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
207207
* `uploadWorkspaceFile` returns the executor-facing `UserFile`, which carries
208208
* neither the folder path nor the persisted timestamps, so the stored record
209209
* is the source for the response projection.
210+
*
211+
* `throwOnError` matters here: by default this reader swallows a query
212+
* failure and returns `null`, which would make a transient blip on the read
213+
* indistinguishable from the row being gone. The row was committed by the
214+
* upload moments earlier on the same primary, so a genuine `null` is an
215+
* invariant break — worth a 500 — while a transient failure should surface
216+
* as itself rather than being reported as a missing file.
210217
*/
211-
const fileRecord = await getWorkspaceFile(workspaceId, userFile.id)
218+
const fileRecord = await getWorkspaceFile(workspaceId, userFile.id, { throwOnError: true })
212219
if (!fileRecord) {
213220
throw new Error(`Uploaded file ${userFile.id} could not be read back`)
214221
}

0 commit comments

Comments
 (0)