From 37c290bb03e234f9689b18c0db21aabb68851125 Mon Sep 17 00:00:00 2001 From: Ayush7614 Date: Sun, 6 Sep 2026 01:17:20 +0530 Subject: [PATCH] fix(server): report a sandbox template that is not valid JSON as a SandboxError --- server/src/computer/sandbox.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/server/src/computer/sandbox.ts b/server/src/computer/sandbox.ts index 3169a973c..80b767602 100644 --- a/server/src/computer/sandbox.ts +++ b/server/src/computer/sandbox.ts @@ -103,13 +103,26 @@ export async function readSandboxTemplate( `COMPUTER_SANDBOX_TEMPLATE_FILE points at ${path}, which cannot be read. That file is what a Bot's computer is cut from; the chart mounts it when computers.mode is sandbox.`, ); } - const parsed = JSON.parse(raw) as Record; - if (!parsed.podTemplate) { + let parsed: unknown; + try { + parsed = JSON.parse(raw); + } catch { + throw new SandboxError( + `${path} is not valid JSON, so there is nothing to make a computer from.`, + ); + } + if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) { + throw new SandboxError( + `${path} is not valid JSON, so there is nothing to make a computer from.`, + ); + } + const podTemplate = (parsed as Record).podTemplate; + if (!podTemplate) { throw new SandboxError( `${path} has no podTemplate, so there is nothing to make a computer from.`, ); } - return parsed; + return parsed as Record; } /** How long a read token is reused before the file is consulted again. */