Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: match edge function error codes to hosted platform #2887

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions internal/functions/serve/templates/main.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
import {
STATUS_CODE,
STATUS_TEXT,
} from "https://deno.land/std/http/status.ts";
import { STATUS_CODE, STATUS_TEXT } from "https://deno.land/std/http/status.ts";
import * as posix from "https://deno.land/std/path/posix/mod.ts";

import * as jose from "https://deno.land/x/[email protected]/index.ts";

const SB_SPECIFIC_ERROR_CODE = {
BootError: STATUS_CODE.ServiceUnavailable, /** Service Unavailable (RFC 7231, 6.6.4) */
WorkerRequestCancelled: STATUS_CODE.BadGateway, /** Bad Gateway (RFC 7231, 6.6.3) */
BootError:
STATUS_CODE.ServiceUnavailable, /** Service Unavailable (RFC 7231, 6.6.4) */
InvalidWorkerResponse:
STATUS_CODE.InternalServerError, /** Internal Server Error (RFC 7231, 6.6.1) */
WorkerLimit: 546, /** Extended */
};

const SB_SPECIFIC_ERROR_TEXT = {
[SB_SPECIFIC_ERROR_CODE.BootError]: "BOOT_ERROR",
[SB_SPECIFIC_ERROR_CODE.WorkerRequestCancelled]: "WORKER_REQUEST_CANCELLED",
[SB_SPECIFIC_ERROR_CODE.InvalidWorkerResponse]: "WORKER_ERROR",
[SB_SPECIFIC_ERROR_CODE.WorkerLimit]: "WORKER_LIMIT",
};

const SB_SPECIFIC_ERROR_REASON = {
[SB_SPECIFIC_ERROR_CODE.BootError]: "Worker failed to boot (please check logs)",
[SB_SPECIFIC_ERROR_CODE.WorkerRequestCancelled]: "Request cancelled by the proxy due to an error or resource limit of worker (please check logs)",
[SB_SPECIFIC_ERROR_CODE.WorkerLimit]: "Worker failed to respond due to an error or resource limit (please check logs)",
}
[SB_SPECIFIC_ERROR_CODE.BootError]:
"Worker failed to boot (please check logs)",
[SB_SPECIFIC_ERROR_CODE.InvalidWorkerResponse]:
"Function exited due to an error (please check logs)",
[SB_SPECIFIC_ERROR_CODE.WorkerLimit]:
"Worker failed to respond due to a resource limit (please check logs)",
};

// OS stuff - we don't want to expose these to the functions.
const EXCLUDED_ENVS = ["HOME", "HOSTNAME", "PATH", "PWD"];
Expand All @@ -34,12 +36,17 @@ const FUNCTIONS_CONFIG_STRING = Deno.env.get(
"SUPABASE_INTERNAL_FUNCTIONS_CONFIG",
)!;

const WALLCLOCK_LIMIT_SEC = parseInt(Deno.env.get("SUPABASE_INTERNAL_WALLCLOCK_LIMIT_SEC"));
const WALLCLOCK_LIMIT_SEC = parseInt(
Deno.env.get("SUPABASE_INTERNAL_WALLCLOCK_LIMIT_SEC"),
);

const DENO_SB_ERROR_MAP = new Map([
[Deno.errors.InvalidWorkerCreation, SB_SPECIFIC_ERROR_CODE.BootError],
[Deno.errors.InvalidWorkerResponse, SB_SPECIFIC_ERROR_CODE.WorkerLimit],
[Deno.errors.WorkerRequestCancelled, SB_SPECIFIC_ERROR_CODE.WorkerRequestCancelled],
[Deno.errors.InvalidWorkerResponse, SB_SPECIFIC_ERROR_CODE.InvalidWorkerResponse],
[
Deno.errors.WorkerRequestCancelled,
SB_SPECIFIC_ERROR_CODE.WorkerLimit,
],
]);

interface FunctionConfig {
Expand Down