Skip to content

Capture exception in edge functions body query - #43628

Merged
joshenlim merged 2 commits into
masterfrom
chore/capture-exception-in-edge-functions-body-query
Mar 11, 2026
Merged

joshenlim merged 2 commits into
masterfrom
chore/capture-exception-in-edge-functions-body-query

Conversation

@joshenlim

Copy link
Copy Markdown
Member

Context

Trying to catch any parsing errors into sentry

@joshenlim
joshenlim requested a review from a team as a code owner March 11, 2026 08:33
@vercel

vercel Bot commented Mar 11, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
design-system Ready Ready Preview, Comment Mar 11, 2026 8:53am
docs Ready Ready Preview, Comment, Open in v0 Mar 11, 2026 8:53am
learn Ready Ready Preview, Comment Mar 11, 2026 8:53am
studio-self-hosted Ready Ready Preview, Comment Mar 11, 2026 8:53am
studio-staging Ready Ready Preview, Comment Mar 11, 2026 8:53am
ui-library Ready Ready Preview, Comment Mar 11, 2026 8:53am
zone-www-dot-com Ready Ready Preview, Comment, Open in v0 Mar 11, 2026 8:53am
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
cms Ignored Ignored Mar 11, 2026 8:53am
studio Ignored Ignored Mar 11, 2026 8:53am

Request Review

@supabase

supabase Bot commented Mar 11, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project xguihxuzqibwxjnimxev because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@coderabbitai

coderabbitai Bot commented Mar 11, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Central YAML (base), Repository UI (inherited), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: c57f9457-d028-4f41-96e2-3b8fd6633b7d

📥 Commits

Reviewing files that changed from the base of the PR and between 310428b and 14347ac.

📒 Files selected for processing (2)
  • .mcp.json
  • apps/studio/data/edge-functions/edge-function-body-query.ts
✅ Files skipped from review due to trivial changes (1)
  • .mcp.json

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling and error reporting for edge function body parsing to reduce failures and capture errors more reliably.
  • Chores
    • Added MCP configuration entry to include the project's MCP server details for deployment/communication.

Walkthrough

The change wraps the multipart stream parsing loop in a try/catch and integrates Sentry: on exception the code captures the error with Sentry (including error data) and rethrows. The successful parsing and return occur inside the try block. The FileData import was restored to support existing multipart handling. No exported or public API declarations were changed.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant EdgeFunction
  participant MultipartParser
  participant Sentry

  Client->>EdgeFunction: Send multipart request
  EdgeFunction->>MultipartParser: Read multipart stream (loop)
  alt parsing succeeds
    MultipartParser-->>EdgeFunction: Return metadata + files
    EdgeFunction-->>Client: Return result
  else parsing error thrown
    MultipartParser--x EdgeFunction: Throw error
    EdgeFunction->>Sentry: captureException(error, { data })
    EdgeFunction--x Client: Rethrow error
  end
Loading

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@alaister alaister left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/studio/data/edge-functions/edge-function-body-query.ts`:
- Around line 61-67: The catch block incorrectly calls Sentry.captureException
with an object; change it to pass the actual Error object (the variable error)
to Sentry.captureException and avoid sending large/sensitive payloads (do not
include data or response). Preferably replace the Sentry call with the existing
captureCriticalError helper from lib/error-reporting.ts (e.g.
captureCriticalError(error, { boundary })) or call
Sentry.captureException(error) and separately add only minimal safe context
(boundary) via Sentry.setContext or similar; ensure you still rethrow the error
afterwards.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Central YAML (base), Repository UI (inherited), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 871adc27-1cd6-4a21-83e9-f17970494c7f

📥 Commits

Reviewing files that changed from the base of the PR and between 9949b75 and 310428b.

📒 Files selected for processing (1)
  • apps/studio/data/edge-functions/edge-function-body-query.ts

Comment on lines +61 to +67
} catch (error) {
if (error instanceof Error)
Sentry.captureException({
message: error.message,
data: { error, data, response, boundary },
})
throw error

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Incorrect Sentry.captureException API usage — error won't be captured.

Sentry.captureException expects an Error object as the first argument, not a plain object. The current code passes { message, data } which will not properly capture the exception. This defeats the PR's purpose.

Proposed fix
   } catch (error) {
-    if (error instanceof Error)
-      Sentry.captureException({
-        message: error.message,
-        data: { error, data, response, boundary },
-      })
+    if (error instanceof Error) {
+      Sentry.captureException(error, {
+        extra: { boundary },
+      })
+    }
     throw error
   }

Note: Avoid including data and response in extras as they may contain large/sensitive payloads. If additional context is needed, consider using the existing captureCriticalError helper from lib/error-reporting.ts.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/studio/data/edge-functions/edge-function-body-query.ts` around lines 61
- 67, The catch block incorrectly calls Sentry.captureException with an object;
change it to pass the actual Error object (the variable error) to
Sentry.captureException and avoid sending large/sensitive payloads (do not
include data or response). Preferably replace the Sentry call with the existing
captureCriticalError helper from lib/error-reporting.ts (e.g.
captureCriticalError(error, { boundary })) or call
Sentry.captureException(error) and separately add only minimal safe context
(boundary) via Sentry.setContext or similar; ensure you still rethrow the error
afterwards.

@github-actions

github-actions Bot commented Mar 11, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Playwright Test Results

passed  160 passed
skipped  4 skipped

Details

stats  164 tests across 20 suites
duration  8 minutes, 10 seconds
commit  14347ac

Skipped tests

Features › sql-editor.spec.ts › SQL Editor › snippet favourite works as expected
Features › sql-editor.spec.ts › SQL Editor › share with team works as expected
Features › sql-editor.spec.ts › SQL Editor › folders works as expected
Features › sql-editor.spec.ts › SQL Editor › other SQL snippets actions work as expected

@joshenlim
joshenlim merged commit c069211 into master Mar 11, 2026
24 checks passed
@joshenlim
joshenlim deleted the chore/capture-exception-in-edge-functions-body-query branch March 11, 2026 09:09
@github-actions

github-actions Bot commented Mar 11, 2026 •

Copy link
Copy Markdown
Contributor

Braintrust eval report

Assistant (master-1773220285)

Score Average Improvements Regressions
Completeness 97.2% (+0pp) 1 🟢 1 🔴
Conciseness 0% (+0pp) - -
Correctness 83.3% (-12pp) - 1 🔴
Docs Faithfulness 66.7% (+11pp) 3 🟢 -
Goal Completion 94.4% (-1pp) - 1 🔴
Tool Usage 100% (+0pp) - -
URL Validity 100% (+0pp) - -
SQL Identifier Quoting 93.8% (-6pp) - 1 🔴
SQL Validity 100% (+0pp) - -
Time_to_first_token 0.2tok (-0.03tok) 11 🟢 1 🔴
Llm_calls 8.42 (+0) 2 🟢 1 🔴
Tool_calls 3 (-0.06) 3 🟢 3 🔴
Errors 0 (+0) - -
Llm_errors 0 (+0) - -
Tool_errors 0 (+0) - -
Prompt_tokens 46618.64tok (-3145.19tok) 7 🟢 5 🔴
Prompt_cached_tokens 27150.22tok (-2538.67tok) 4 🟢 8 🔴
Prompt_cache_creation_tokens 0tok (+0tok) - -
Completion_tokens 2778.5tok (+65.44tok) 7 🟢 5 🔴
Completion_reasoning_tokens 2026.67tok (+1.78tok) 6 🟢 6 🔴
Completion_accepted_prediction_tokens 0tok (+0tok) - -
Completion_rejected_prediction_tokens 0tok (+0tok) - -
Completion_audio_tokens 0tok (+0tok) - -
Total_tokens 49397.14tok (-3079.75tok) 9 🟢 3 🔴
Estimated_cost 0.01$ (0$) 7 🟢 4 🔴
Duration 50.51s (-7.75s) 11 🟢 1 🔴
Llm_duration 99.47s (-15.64s) 11 🟢 1 🔴

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.

3 participants