firecrawl/open-lovable · error · Error

Failed to list files

Error message

Failed to list files

What it means

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.

Source

Thrown at app/api/get-sandbox-files/route.ts:44

        '-name', 'node_modules', '-prune', '-o',
        '-name', '.git', '-prune', '-o',
        '-name', 'dist', '-prune', '-o',
        '-name', 'build', '-prune', '-o',
        '-type', 'f',
        '(',
        '-name', '*.jsx',
        '-o', '-name', '*.js',
        '-o', '-name', '*.tsx',
        '-o', '-name', '*.ts',
        '-o', '-name', '*.css',
        '-o', '-name', '*.json',
        ')',
        '-print'
      ]
    });
    
    if (findResult.exitCode !== 0) {
      throw new Error('Failed to list files');
    }
    
    const fileList = (await findResult.stdout()).split('\n').filter((f: string) => f.trim());
    console.log('[get-sandbox-files] Found', fileList.length, 'files');
    
    // Read content of each file (limit to reasonable sizes)
    const filesContent: Record<string, string> = {};
    
    for (const filePath of fileList) {
      try {
        // Check file size first
        const statResult = await global.activeSandbox.runCommand({
          cmd: 'stat',
          args: ['-f', '%z', filePath]
        });
        
        if (statResult.exitCode === 0) {
          const fileSize = parseInt(await statResult.stdout());

View on GitHub (pinned to 69bd93bae7)

Solutions

  1. Run the find command manually in the sandbox to see stderr (the route discards it, so add stderr logging first)
  2. Verify the project directory exists in the sandbox before listing; recreate the sandbox and re-apply code if it was reset
  3. Capture stderr in the error message for diagnosability
  4. Add a fallback listing method (e.g. `ls -R` or the SDK's files.list API) if find is unavailable

Example fix

// before
if (findResult.exitCode !== 0) {
  throw new Error('Failed to list files');
}
// after
if (findResult.exitCode !== 0) {
  const errText = await findResult.stderr();
  throw new Error(`Failed to list files: exit ${findResult.exitCode}: ${errText}`);
}
Defensive patterns

Strategy: try-catch

Validate before calling

const dirExists = await sandbox.runCommand({ cmd: 'bash', args: ['-c', 'test -d /project && echo yes || echo no'] });
if ((await dirExists.stdout()).trim() !== 'yes') throw new Error('Project directory missing in sandbox — recreate sandbox');

Type guard

function commandOk(r: { exitCode: number }): boolean { return r.exitCode === 0; }

Try / catch

try {
  const files = await getSandboxFiles();
} catch (e) {
  if (e.message === 'Failed to list files') {
    await recreateSandboxAndReapplyCode();
    return getSandboxFiles();
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of firecrawl/open-lovable@69bd93bae7 (2026-08-28). Data as JSON: /api/errors/324ca5a5c5e68bf0. Report an issue: GitHub.