Skip to content

fix(table): return 400 instead of 500 on empty batch insert#4329

Merged
waleedlatif1 merged 1 commit intostagingfrom
waleedlatif1/investigate-run-error
Apr 29, 2026
Merged

fix(table): return 400 instead of 500 on empty batch insert#4329
waleedlatif1 merged 1 commit intostagingfrom
waleedlatif1/investigate-run-error

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

Summary

  • POST /api/table/[tableId]/rows called handleBatchInsert without await, so ZodError rejections (e.g. empty rows array) bypassed the route's try/catch and were caught by withRouteHandler as an unhandled error — returning a generic 500 "Internal server error"
  • Add await so validation errors surface as proper 400s with the actual message (e.g. "At least one row is required")

Type of Change

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

The POST /api/table/[tableId]/rows handler called handleBatchInsert
without await, so ZodError rejections (e.g. empty rows array) bypassed
the route's try/catch and were caught by withRouteHandler as an
unhandled error, returning a generic 500 "Internal server error". Add
await so validation errors surface as 400s with the actual message.
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 29, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Apr 29, 2026 0:17am

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 29, 2026

PR Summary

Low Risk
Low risk, single-line change to POST /api/table/[tableId]/rows control flow so batch-insert validation errors are handled as intended rather than surfacing as unhandled 500s.

Overview
Fixes batch row inserts in POST /api/table/[tableId]/rows by awaiting handleBatchInsert().

This ensures Zod/validation failures in batch insert requests (e.g., empty rows) propagate through the route’s error handling and return a proper 400 response instead of a generic 500.

Reviewed by Cursor Bugbot for commit 989ecd1. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 29, 2026

Greptile Summary

This PR adds a missing await on the handleBatchInsert call inside the POST route handler. Without await, a ZodError thrown synchronously inside handleBatchInsert (e.g. from an empty rows: [] array failing the .min(1) constraint) bypassed the outer try/catch and was surfaced as an unhandled rejection by withRouteHandler, producing a generic 500. With await the rejection propagates correctly into the outer catch block, which maps ZodError to a 400 with validation details.

Confidence Score: 5/5

This PR is safe to merge — it's a minimal, correct one-word fix with no regressions.

Single-character change (await) that correctly fixes the unhandled-rejection bug. The outer try/catch already contains the ZodError → 400 mapping, so the fix is complete with no side effects. No schema, data, or auth changes.

No files require special attention.

Important Files Changed

Filename Overview
apps/sim/app/api/table/[tableId]/rows/route.ts Adds await to handleBatchInsert call so ZodErrors (e.g. empty rows array) propagate to the outer try/catch and return 400 instead of bubbling as an unhandled rejection through withRouteHandler as a 500.

Sequence Diagram

sequenceDiagram
    participant Client
    participant withRouteHandler
    participant POST Handler
    participant handleBatchInsert
    participant ZodSchema

    Client->>withRouteHandler: POST /api/table/[tableId]/rows {rows:[]}
    withRouteHandler->>POST Handler: invoke

    rect rgb(200, 240, 200)
        Note over POST Handler,ZodSchema: After fix (await present)
        POST Handler->>handleBatchInsert: await handleBatchInsert(...)
        handleBatchInsert->>ZodSchema: BatchInsertRowsSchema.parse({rows:[]})
        ZodSchema-->>handleBatchInsert: throws ZodError
        handleBatchInsert-->>POST Handler: rejected Promise
        POST Handler->>POST Handler: catch(error) — ZodError instanceof z.ZodError
        POST Handler-->>Client: 400 { error: "Validation error", details: [...] }
    end

    rect rgb(255, 200, 200)
        Note over POST Handler,ZodSchema: Before fix (no await)
        POST Handler->>handleBatchInsert: handleBatchInsert(...) [no await]
        handleBatchInsert->>ZodSchema: BatchInsertRowsSchema.parse({rows:[]})
        ZodSchema-->>handleBatchInsert: throws ZodError
        handleBatchInsert-->>POST Handler: unhandled Promise rejection
        POST Handler-->>withRouteHandler: uncaught rejection
        withRouteHandler-->>Client: 500 "Internal server error"
    end
Loading

Reviews (1): Last reviewed commit: "fix(table): return 400 instead of 500 on..." | Re-trigger Greptile

@waleedlatif1 waleedlatif1 merged commit 3784f54 into staging Apr 29, 2026
14 checks passed
@waleedlatif1 waleedlatif1 deleted the waleedlatif1/investigate-run-error branch April 29, 2026 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant