From 0a39249851cd658f183ec4afee902e07c8e70c8b Mon Sep 17 00:00:00 2001 From: riz Date: Wed, 19 Nov 2025 22:51:56 +0000 Subject: [PATCH] Fix cache initialization and add better error handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Initialize g.cache early to prevent undefined access errors - Add detailed error handling for metadata.json parsing - Prevent cascade failures when ZIP deployment fails - Add JSON content preview for debugging parsing issues 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- pkgs/utils/deploy.ts | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/pkgs/utils/deploy.ts b/pkgs/utils/deploy.ts index 3bbe774..b35e83c 100644 --- a/pkgs/utils/deploy.ts +++ b/pkgs/utils/deploy.ts @@ -89,17 +89,19 @@ export const deploy = { throw new Error(`No deployment file found for timestamp: ${ts}`); } + // Initialize cache early to prevent undefined access errors + console.log(`[DEBUG] Setting up cache and compression...`); + g.cache = { + br: {}, + gz: {}, + br_progress: { + pending: {}, + running: false, + timeout: null, + }, + }; + if (g.deploy.content) { - console.log(`[DEBUG] Setting up cache and compression...`); - g.cache = { - br: {}, - gz: {}, - br_progress: { - pending: {}, - running: false, - timeout: null, - }, - }; startBrCompress(); console.log(`[DEBUG] Compression started`); @@ -273,7 +275,16 @@ export const deploy = { if (entry.filename === 'metadata.json') { console.log(`[DEBUG] Found metadata.json, parsing content...`); const metadataStr = new TextDecoder().decode(fileContent); - const metadata = JSON.parse(metadataStr); + let metadata; + + try { + metadata = JSON.parse(metadataStr); + console.log(`[DEBUG] Successfully parsed metadata.json`); + } catch (jsonError) { + console.error(`[ERROR] Failed to parse metadata.json: ${jsonError.message}`); + console.error(`[ERROR] JSON content preview:`, metadataStr.substring(0, 200)); + throw new Error(`Invalid JSON in metadata.json: ${jsonError.message}`); + } console.log(`[DEBUG] Parsed metadata:`, { layouts: metadata.layouts?.length || 0,