Skip to content

fix(studio): surface real error message from self-hosted edge function test - #47836

Closed
shkuls wants to merge 7 commits into
supabase:masterfrom
shkuls:fix/self-hosted-edge-function-test-error-message
Closed

shkuls wants to merge 7 commits into
supabase:masterfrom
shkuls:fix/self-hosted-edge-function-test-error-message

Conversation

@shkuls

@shkuls shkuls commented Jul 10, 2026 •

Copy link
Copy Markdown

Fixes #47835

I have read the CONTRIBUTING.md file.

YES

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

On self-hosted Supabase, the Edge Functions Test panel shows the same generic Edge function returned an error message for every failure, regardless of cause. The proxy endpoint (pages/api/edge-functions/test.ts) only checked an error key when parsing the edge runtime's JSON error body, but self-hosted's Kong-fronted edge runtime returns errors shaped as {"message": "..."}, so the key never matched and the real reason was always discarded. See #47835 for full repro and before/after proof.

What is the new behavior?

The proxy now checks message (self-hosted shape) first, falls back to error (platform shape), then the generic string as a last resort. Extracted the parsing logic into a pure getEdgeFunctionErrorMessage() helper in lib/api/edgeFunctions.ts, alongside the existing isValidEdgeFunctionURL, covered by unit tests for the shape permutations (self-hosted shape, platform shape, both present, non-string/empty fields, non-JSON body, empty body).

Additional context

  • getEdgeFunctionErrorMessage unit tests pass (apps/studio/lib/api/edgeFunctions.test.ts)
  • tsc --noEmit clean
  • Verified live against a local self-hosted stack: a request to a function whose edge runtime container was down previously showed Edge function returned an error; after the fix it shows the real reason, name resolution failed

Summary by CodeRabbit

  • Bug Fixes
    • Improved error messages returned when edge function requests fail, including the full upstream response details.
    • Standardized error response formatting for invalid authentication tokens, missing function names, and function startup failures.
    • Preserved upstream status codes while providing more consistent JSON error payloads.

shkuls added 2 commits July 10, 2026 23:47
…n test

Self-hosted's Kong-fronted edge runtime returns errors as
{"message": "..."}, but the test-invoke proxy only checked
errorBody?.error. This meant every failed test request in self-hosted
(network issue, thrown exception, timeout, etc.) showed the same
generic "Edge function returned an error" instead of the actual cause.
Move the error-shape handling out of the API route into a pure,
testable getEdgeFunctionErrorMessage() helper in lib/api/edgeFunctions.ts,
matching the existing pattern used by isValidEdgeFunctionURL in the same
file. Covers self-hosted vs platform error shapes, non-string fields,
malformed JSON, and empty bodies.
@shkuls
shkuls requested a review from a team as a code owner July 10, 2026 18:50
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for contributing to Supabase! ❤️ Our team will review your PR.

A few tips for a smoother review process:

  • If you have a local version of the repo, run pnpm run format to make sure formatting checks pass.
  • Once we've reviewed your PR, please don't trivially merge master (don't click Update branch if there are no merge conflicts to be fixed). This invalidates any pre-merge checks we've run.

@vercel

vercel Bot commented Jul 10, 2026

Copy link
Copy Markdown

@shkuls is attempting to deploy a commit to the Supabase Team on Vercel.

A member of the Team first needs to authorize it.

@vercel

vercel Bot commented Jul 10, 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 Jul 11, 2026 3:41pm

Request Review

@coderabbitai

coderabbitai Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The changes standardize edge function runtime error payloads on the error field and update the Studio test proxy to derive non-OK messages through getEdgeFunctionErrorMessage, while preserving upstream status codes and response structure.

Changes

Edge Function Error Handling

Layer / File(s) Summary
Runtime error payload contract
docker/volumes/functions/main/index.ts
JWT, missing-function-name, and worker-creation error responses now use { error: ... } instead of { msg: ... }.
Test proxy error extraction
apps/studio/pages/api/edge-functions/test.ts
Non-OK upstream responses use getEdgeFunctionErrorMessage(responseBody) for error.message while retaining the upstream status.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main fix: surfacing the real self-hosted edge function error in Studio.
Description check ✅ Passed All required template sections are present and filled with relevant bug-fix details.
Linked Issues check ✅ Passed The changes address #47835 by normalizing error payloads so Studio can surface the real failure reason.
Out of Scope Changes check ✅ Passed The Studio and self-hosted worker edits are directly tied to the reported error-shape bug.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@aantti aantti self-assigned this Jul 10, 2026
@aantti aantti added cli Related to supabase/cli self-hosted Related to self-hosted Supabase labels Jul 10, 2026
@aantti

aantti commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Thanks, but tbf, I think it's best to fix the main worker for both CLI and self-hosted vs patching Studio :)

See the following:

  • CLI - see apps/cli/src/shared/functions/serve.main.ts (and the legacy CLI-go used this, I think - apps/cli-go/internal/functions/serve/templates/main.bundled.js)
  • Self-hosted - see docker/volumes/functions/main/index.ts

@shkuls

shkuls commented Jul 11, 2026 •

Copy link
Copy Markdown
Author

Agreed, patching at the source is the right call. I'll open PRs to normalize those to error.

One thing worth flagging tho, the specific failure in the issue (name resolution failed) never actually reaches the worker script. It's Kong's own 503 when it can't route to the edge-runtime container (confirmed via the Server: kong response header). That happens upstream of any worker code, so no worker-side fix can normalize it. This is the same for any errors from user's own functions.

Hence this Studio defensive parsing is necessary for that class of errors.

…nses

The self-hosted docker-compose functions main worker returned failures
as { msg: "..." }, inconsistent with the platform gateway's { error: "..." }
shape that Studio's edge function test panel checks for.

Aligns JWT verification, missing-function-name, and worker-creation
failures to { error: "..." }, matching platform. Complements the CLI
fix in supabase/cli (apps/cli/src/shared/functions/serve.main.ts) and
Studio's defensive parsing in lib/api/edgeFunctions.ts, which stays
necessary for gateway-level errors (e.g. Kong routing failures) that
never reach this worker script at all.
@aantti

aantti commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

@shkuls Correct, when no functions container running or something is wrong with the upstream, Kong will return message... But, it's also that Kong is going to be deprecated and Envoy will become the default API gateway for self-hosted, and it responds with non-JSON: no healthy upstream - jfyi :)

@shkuls

shkuls commented Jul 11, 2026

Copy link
Copy Markdown
Author

Oh I see, did not know about Kong being deprecated. In that case, wdyt should I still keep the parsing as it also handles a user function emitting error ( I have faced this in the past as well where I had to open the dashboard to see the error while curl-ing from my terminal)

@aantti

aantti commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

I'm still not sure this change to Studio is required, btw, @shkuls. This is too much customization.

@aantti aantti removed their assignment Jul 11, 2026
@shkuls

shkuls commented Jul 11, 2026

Copy link
Copy Markdown
Author

I see @aanti :) I will remove the getEdgeFunctionErrorMessage() and just keep the fix at the source, that should make this a very small PR.

@aantti

aantti commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

wdyt should I still keep the parsing

My preference would be to align CLI's and self-hosted's main/index.ts main worker with regard to the emitted errors (probably most common issue of a function not found or a function failing?), and accept the API gateway failures on reaching the functions container as-is - it's a bit too specific to handle it in the Studio code.

@shkuls

shkuls commented Jul 11, 2026

Copy link
Copy Markdown
Author

Sure, thanks for your review. The error parsing still doesn't cover all the cases (and we possibly cannot ig) so its better to remove it. I will remove the specific parsing and revert the test.ts to to a single error check.

shkuls added 2 commits July 11, 2026 21:08
Per aantti's feedback on supabase#47836, gateway-level failures (e.g. Kong
routing errors) happen before any worker script runs and can't be
fixed at the source, so special-casing them in Studio is unnecessary
customization. The self-hosted worker itself (docker/volumes/functions/main/index.ts)
now emits `error` consistently, so the original single-key check is
sufficient.
@shkuls

shkuls commented Jul 11, 2026

Copy link
Copy Markdown
Author

Done @aantti :) diff's down to just the source fix. Also I split the docs examples with the same msg/error bug into their own PR: #47849.

@7ttp 7ttp self-assigned this Jul 11, 2026
@shkuls

shkuls commented Jul 14, 2026

Copy link
Copy Markdown
Author

any updates here @7ttp ?

@7ttp 7ttp 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.

had another look after the discussions

I don’t think msg → error is the right direction here
could we instead align this w the { code, message } pattern and include
sb-error-code for failures, as we’re doing elsewhere?

thoughts? @aantti

@7ttp 7ttp 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.

as mentioned earlier msg -> error isn't the right approach here

we're currently working on this here: #48012
also we kinda nudged studio a bit: #47920

Thanks a ton! for the pr(s) tho &
for ur great efforts towards making Supabase better :) 💚

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli Related to supabase/cli self-hosted Related to self-hosted Supabase

Projects

Development

Successfully merging this pull request may close these issues.

Edge Functions Test panel always shows generic error for non-platform, hiding the real failure reason

3 participants