{"record":{"id":"324ca5a5c5e68bf0","repo":"firecrawl/open-lovable","slug":"failed-to-list-files","errorCode":null,"errorMessage":"Failed to list files","messagePattern":"Failed to list files","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"app/api/get-sandbox-files/route.ts","lineNumber":44,"sourceCode":"        '-name', 'node_modules', '-prune', '-o',\n        '-name', '.git', '-prune', '-o',\n        '-name', 'dist', '-prune', '-o',\n        '-name', 'build', '-prune', '-o',\n        '-type', 'f',\n        '(',\n        '-name', '*.jsx',\n        '-o', '-name', '*.js',\n        '-o', '-name', '*.tsx',\n        '-o', '-name', '*.ts',\n        '-o', '-name', '*.css',\n        '-o', '-name', '*.json',\n        ')',\n        '-print'\n      ]\n    });\n    \n    if (findResult.exitCode !== 0) {\n      throw new Error('Failed to list files');\n    }\n    \n    const fileList = (await findResult.stdout()).split('\\n').filter((f: string) => f.trim());\n    console.log('[get-sandbox-files] Found', fileList.length, 'files');\n    \n    // Read content of each file (limit to reasonable sizes)\n    const filesContent: Record<string, string> = {};\n    \n    for (const filePath of fileList) {\n      try {\n        // Check file size first\n        const statResult = await global.activeSandbox.runCommand({\n          cmd: 'stat',\n          args: ['-f', '%z', filePath]\n        });\n        \n        if (statResult.exitCode === 0) {\n          const fileSize = parseInt(await statResult.stdout());","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/firecrawl/open-lovable/blob/69bd93bae7a9c97ef989eb70aabe6797fb3dac89/app/api/get-sandbox-files/route.ts#L26-L62","documentation":"Thrown by GET /api/get-sandbox-files when a `find` command run inside the sandbox exits non-zero while enumerating project files. The stderr is not captured, so the actual cause (missing directory, find unavailable, permission denied) must be inferred or checked in the sandbox.","triggerScenarios":"GET /api/get-sandbox-files where the in-sandbox `find` over the project directory fails: the project directory no longer exists (sandbox restarted/reset), the find binary is missing, or the command exceeded args/resources.","commonSituations":"Sandbox timed out and was recreated, losing the project directory; working directory path changed between app versions; extremely large trees making the command slow until the client aborts.","solutions":["Run the find command manually in the sandbox to see stderr (the route discards it, so add stderr logging first)","Verify the project directory exists in the sandbox before listing; recreate the sandbox and re-apply code if it was reset","Capture stderr in the error message for diagnosability","Add a fallback listing method (e.g. `ls -R` or the SDK's files.list API) if find is unavailable"],"exampleFix":"// before\nif (findResult.exitCode !== 0) {\n  throw new Error('Failed to list files');\n}\n// after\nif (findResult.exitCode !== 0) {\n  const errText = await findResult.stderr();\n  throw new Error(`Failed to list files: exit ${findResult.exitCode}: ${errText}`);\n}","handlingStrategy":"try-catch","validationCode":"const dirExists = await sandbox.runCommand({ cmd: 'bash', args: ['-c', 'test -d /project && echo yes || echo no'] });\nif ((await dirExists.stdout()).trim() !== 'yes') throw new Error('Project directory missing in sandbox — recreate sandbox');","typeGuard":"function commandOk(r: { exitCode: number }): boolean { return r.exitCode === 0; }","tryCatchPattern":"try {\n  const files = await getSandboxFiles();\n} catch (e) {\n  if (e.message === 'Failed to list files') {\n    await recreateSandboxAndReapplyCode();\n    return getSandboxFiles();\n  }\n  throw e;\n}","preventionTips":["Capture stderr in the error message so the real cause is visible","Check directory existence before running find","Recreate and re-provision the sandbox after restarts — /tmp and project dirs are ephemeral","Add a health check endpoint that verifies the sandbox filesystem before file operations"],"tags":["sandbox","shell-command","filesystem"],"backgroundTag":"command-exit-nonzero","analyzedSha":"69bd93bae7a9c97ef989eb70aabe6797fb3dac89","analyzedAt":"2026-08-28T22:20:32.339Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}