{"record":{"id":"a73bc398aafb72dd","repo":"firecrawl/open-lovable","slug":"failed-to-create-zip-error","errorCode":null,"errorMessage":"Failed to create zip: ${error}","messagePattern":"Failed to create zip: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"app/api/create-zip/route.ts","lineNumber":26,"sourceCode":"  try {\n    if (!global.activeSandbox) {\n      return NextResponse.json({ \n        success: false, \n        error: 'No active sandbox' \n      }, { status: 400 });\n    }\n    \n    console.log('[create-zip] Creating project zip...');\n    \n    // Create zip file in sandbox using standard commands\n    const zipResult = await global.activeSandbox.runCommand({\n      cmd: 'bash',\n      args: ['-c', `zip -r /tmp/project.zip . -x \"node_modules/*\" \".git/*\" \".next/*\" \"dist/*\" \"build/*\" \"*.log\"`]\n    });\n    \n    if (zipResult.exitCode !== 0) {\n      const error = await zipResult.stderr();\n      throw new Error(`Failed to create zip: ${error}`);\n    }\n    \n    const sizeResult = await global.activeSandbox.runCommand({\n      cmd: 'bash',\n      args: ['-c', `ls -la /tmp/project.zip | awk '{print $5}'`]\n    });\n    \n    const fileSize = await sizeResult.stdout();\n    console.log(`[create-zip] Created project.zip (${fileSize.trim()} bytes)`);\n    \n    // Read the zip file and convert to base64\n    const readResult = await global.activeSandbox.runCommand({\n      cmd: 'base64',\n      args: ['/tmp/project.zip']\n    });\n    \n    if (readResult.exitCode !== 0) {\n      const error = await readResult.stderr();","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/firecrawl/open-lovable/blob/69bd93bae7a9c97ef989eb70aabe6797fb3dac89/app/api/create-zip/route.ts#L8-L44","documentation":"Thrown when a `zip -r /tmp/project.zip` command executed inside the sandbox exits with a non-zero status. The command's stderr is captured and embedded in the message, so the actual zip failure reason (missing files, no write permission, zip binary missing) is in the error text.","triggerScenarios":"POST /api/create-zip where the in-sandbox `zip` command fails: the `zip` binary is not installed in the sandbox image, the working directory is empty or unreadable, or /tmp is not writable.","commonSituations":"Minimal/custom sandbox images without the zip utility; sandbox filesystem reset so the project directory is gone; permissions issues after the sandbox restarted mid-session.","solutions":["Read the `error` field of the thrown message — it contains the zip stderr (e.g. 'zip: command not found')","Install zip in the sandbox image or fall back to a different compressor (`tar czf` is usually available)","Verify the project directory exists and is non-empty before zipping","Retry by re-creating the sandbox if the filesystem was reset"],"exampleFix":"// before\nif (zipResult.exitCode !== 0) {\n  const error = await zipResult.stderr();\n  throw new Error(`Failed to create zip: ${error}`);\n}\n// after\nif (zipResult.exitCode !== 0) {\n  let error = await zipResult.stderr();\n  if (/command not found/.test(error)) {\n    await global.activeSandbox.runCommand({ cmd: 'bash', args: ['-c', 'apt-get install -y zip'] });\n    // retry zip command...\n  }\n  throw new Error(`Failed to create zip: ${error}`);\n}","handlingStrategy":"validation","validationCode":"const which = await sandbox.runCommand({ cmd: 'bash', args: ['-c', 'command -v zip'] });\nif (which.exitCode !== 0) throw new Error('zip is not installed in this sandbox image');","typeGuard":"function succeeded(r: { exitCode: number }): boolean { return r.exitCode === 0; }","tryCatchPattern":"try {\n  const zip = await createProjectZip();\n} catch (e) {\n  if (e.message.includes('command not found')) {\n    // install zip or fall back to tar\n  } else {\n    throw e;\n  }\n}","preventionTips":["Bake zip (or use tar) into the sandbox image used by the app","Capture and include stderr in thrown errors for diagnosability","Check the project directory is non-empty before zipping","Treat /tmp as ephemeral: create and consume the zip within one request"],"tags":["sandbox","shell-command","zip"],"backgroundTag":"command-exit-nonzero","analyzedSha":"69bd93bae7a9c97ef989eb70aabe6797fb3dac89","analyzedAt":"2026-08-28T22:20:32.339Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}