{"record":{"id":"1e6fefdc7429527b","repo":"firecrawl/open-lovable","slug":"failed-to-read-zip-file-error","errorCode":null,"errorMessage":"Failed to read zip file: ${error}","messagePattern":"Failed to read zip file: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"app/api/create-zip/route.ts","lineNumber":45,"sourceCode":"    }\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();\n      throw new Error(`Failed to read zip file: ${error}`);\n    }\n    \n    const base64Content = (await readResult.stdout()).trim();\n    \n    // Create a data URL for download\n    const dataUrl = `data:application/zip;base64,${base64Content}`;\n    \n    return NextResponse.json({\n      success: true,\n      dataUrl,\n      fileName: 'vercel-sandbox-project.zip',\n      message: 'Zip file created successfully'\n    });\n    \n  } catch (error) {\n    console.error('[create-zip] Error:', error);\n    return NextResponse.json(\n      { ","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/firecrawl/open-lovable/blob/69bd93bae7a9c97ef989eb70aabe6797fb3dac89/app/api/create-zip/route.ts#L27-L63","documentation":"Thrown when the sandbox command `base64 /tmp/project.zip` exits non-zero while trying to encode the freshly created zip for download. It means the zip either wasn't created by the previous step or can't be read (missing file, missing base64 binary, permissions).","triggerScenarios":"POST /api/create-zip where /tmp/project.zip does not exist (the earlier zip step failed silently or ran in a different sandbox), the file is unreadable, or `base64` is unavailable in the image.","commonSituations":"Sandbox re-created between the zip and read steps so /tmp was wiped; coreutils variant without `base64` (e.g. busybox requiring `base64` args differences); permission errors on /tmp.","solutions":["Check the `error` field in the message — stderr names the real cause (e.g. 'No such file or directory')","Ensure the zip step succeeded and ran in the same sandbox instance before the base64 step","Verify the file exists first (`test -f /tmp/project.zip`) and fail earlier with a clearer message","Use `base64 -w 0` or `openssl base64` if line-wrapping or binary availability is the problem"],"exampleFix":"// before\nif (readResult.exitCode !== 0) {\n  const error = await readResult.stderr();\n  throw new Error(`Failed to read zip file: ${error}`);\n}\n// after\nconst check = await global.activeSandbox.runCommand({ cmd: 'bash', args: ['-c', 'test -f /tmp/project.zip && echo ok'] });\nif ((await check.stdout()).trim() !== 'ok') {\n  throw new Error('/tmp/project.zip missing — zip step failed or sandbox was recreated');\n}\nif (readResult.exitCode !== 0) {\n  const error = await readResult.stderr();\n  throw new Error(`Failed to read zip file: ${error}`);\n}","handlingStrategy":"validation","validationCode":"const exists = await sandbox.runCommand({ cmd: 'bash', args: ['-c', 'test -f /tmp/project.zip && echo yes || echo no'] });\nif ((await exists.stdout()).trim() !== 'yes') throw new Error('/tmp/project.zip missing before read step');","typeGuard":"function commandOk(r: { exitCode: number }): boolean { return r.exitCode === 0; }","tryCatchPattern":"try {\n  const dataUrl = await downloadProjectZip();\n} catch (e) {\n  if (e.message.includes('Failed to read zip file')) {\n    // re-run the zip step in the same sandbox before giving up\n  }\n  throw e;\n}","preventionTips":["Run zip and base64 against the same sandbox instance in one request","Verify file existence with `test -f` before encoding","Prefer the SDK's file-download API over shell base64 when available","Include stderr in the thrown message to distinguish missing-file vs missing-binary"],"tags":["sandbox","shell-command","file-read"],"backgroundTag":"file-not-found","analyzedSha":"69bd93bae7a9c97ef989eb70aabe6797fb3dac89","analyzedAt":"2026-08-28T22:20:32.339Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}