Skip to content

Commit d8e1c25

Browse files
committed
fix(providers): guard Gemini upload response name before polling
ai.files.upload returns name as string | undefined; guard it (instead of an as-string cast) so a missing name surfaces a clear error at the upload site rather than an opaque files.get failure on the first poll.
1 parent fc9d1cd commit d8e1c25

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

apps/sim/providers/file-attachments.server.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,18 @@ async function uploadGeminiFile(
220220
const blob = await downloadFileForUpload(file, maxBytes)
221221

222222
let uploaded = await ai.files.upload({ file: blob, config: { mimeType, abortSignal: signal } })
223+
if (!uploaded.name) {
224+
throw new Error(`Gemini upload for "${file.name}" returned no file name`)
225+
}
226+
const uploadedName = uploaded.name
223227

224228
const deadline = Date.now() + GEMINI_PROCESSING_TIMEOUT_MS
225229
while (uploaded.state === FileState.PROCESSING) {
226230
if (Date.now() > deadline) {
227231
throw new Error(`Gemini file processing timed out for "${file.name}"`)
228232
}
229233
await sleep(GEMINI_POLL_INTERVAL_MS)
230-
uploaded = await ai.files.get({ name: uploaded.name as string })
234+
uploaded = await ai.files.get({ name: uploadedName })
231235
}
232236

233237
if (uploaded.state === FileState.FAILED || !uploaded.uri) {

0 commit comments

Comments
 (0)