Skip to content

Commit

Permalink
fix: match edge function error codes to hosted platform (#2887)
Browse files Browse the repository at this point in the history
  • Loading branch information
laktek authored Nov 15, 2024
2 parents 8f3034e + 1ab41c0 commit 080e382
Showing 1 changed file with 21 additions and 14 deletions.
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

0 comments on commit 080e382

Please sign in to comment.