Fix cache initialization and add better error handling

- 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 <noreply@anthropic.com>
This commit is contained in:
riz 2025-11-19 22:51:56 +00:00
parent c13e1118ca
commit 0a39249851
1 changed files with 22 additions and 11 deletions

View File

@ -89,17 +89,19 @@ export const deploy = {
throw new Error(`No deployment file found for timestamp: ${ts}`); 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) { if (g.deploy.content) {
console.log(`[DEBUG] Setting up cache and compression...`);
g.cache = {
br: {},
gz: {},
br_progress: {
pending: {},
running: false,
timeout: null,
},
};
startBrCompress(); startBrCompress();
console.log(`[DEBUG] Compression started`); console.log(`[DEBUG] Compression started`);
@ -273,7 +275,16 @@ export const deploy = {
if (entry.filename === 'metadata.json') { if (entry.filename === 'metadata.json') {
console.log(`[DEBUG] Found metadata.json, parsing content...`); console.log(`[DEBUG] Found metadata.json, parsing content...`);
const metadataStr = new TextDecoder().decode(fileContent); 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:`, { console.log(`[DEBUG] Parsed metadata:`, {
layouts: metadata.layouts?.length || 0, layouts: metadata.layouts?.length || 0,