Skip to content

Commit 1516b74

Browse files
waleedlatif1claude
andcommitted
fix(knowledge): guard against empty createDocumentRecords result
Add safety check before accessing firstDocument to prevent TypeError and data loss if createDocumentRecords unexpectedly returns empty. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3e4a6e4 commit 1516b74

File tree

1 file changed

+4
-0
lines changed
  • apps/sim/app/api/knowledge/[id]/documents/upsert

1 file changed

+4
-0
lines changed

apps/sim/app/api/knowledge/[id]/documents/upsert/route.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ export async function POST(req: NextRequest, { params }: { params: Promise<{ id:
151151
}
152152

153153
const firstDocument = createdDocuments[0]
154+
if (!firstDocument) {
155+
logger.error(`[${requestId}] createDocumentRecords returned empty array unexpectedly`)
156+
return NextResponse.json({ error: 'Failed to create document record' }, { status: 500 })
157+
}
154158

155159
processDocumentsWithQueue(
156160
createdDocuments,

0 commit comments

Comments
 (0)