firecrawl/open-lovable · error · Error
Failed to read file: ${stderr}
Error message
Failed to read file: ${stderr} What it means
readFile() shells out via sandbox.runCommand (typically `cat <path>`) and inspects result.exitCode. If the command exits non-zero, the accumulated stderr is embedded in this Error. It reports a failed read, most commonly a missing file or a path outside the sandbox working directory (/vercel/sandbox).
Source
Thrown at lib/sandbox/providers/vercel-provider.ts:229
} else {
stdout = result.stdout || '';
}
} catch (e) {
stdout = '';
}
try {
if (typeof result.stderr === 'function') {
stderr = await result.stderr();
} else {
stderr = result.stderr || '';
}
} catch (e) {
stderr = '';
}
if (result.exitCode !== 0) {
throw new Error(`Failed to read file: ${stderr}`);
}
return stdout;
}
async listFiles(directory: string = '/vercel/sandbox'): Promise<string[]> {
if (!this.sandbox) {
throw new Error('No active sandbox');
}
const result = await this.sandbox.runCommand({
cmd: 'sh',
args: ['-c', `find ${directory} -type f -not -path "*/node_modules/*" -not -path "*/.git/*" -not -path "*/.next/*" -not -path "*/dist/*" -not -path "*/build/*" | sed "s|^${directory}/||"`],
cwd: '/'
});
// Handle stdout - it might be a function in Vercel SDK
let stdout = '';View on GitHub (pinned to 69bd93bae7)
Solutions
- Verify the file exists first (listFiles or writeFile tracking) before reading
- Use absolute paths under /vercel/sandbox or ensure relative paths resolve from that cwd
- Re-run setupViteApp / rewrite the file if it was expected to be scaffolded
- Inspect stderr in the message to distinguish missing-file vs permission/parse issues
Example fix
// before
const src = await sandbox.readFile('src/App.tsx');
// after
const files = await sandbox.listFiles();
if (!files.includes('src/App.tsx')) throw new Error('File not scaffolded yet');
const src = await sandbox.readFile('/vercel/sandbox/src/App.tsx'); Defensive patterns
Strategy: validation
Validate before calling
const files = await sandbox.listFiles();
if (!files.includes(relPath)) throw new Error(`File ${relPath} does not exist in sandbox`); Type guard
function isReadablePath(p: string): boolean { return typeof p === 'string' && p.length > 0 && !p.includes('\\') && !p.includes('..'); } Try / catch
try {
return await sandbox.readFile(path);
} catch (e) {
if (e.message.startsWith('Failed to read file:')) throw new FileNotFoundError(path, e.message);
throw e;
} Prevention
- Check listFiles() output before reading arbitrary paths
- Prefer absolute paths under /vercel/sandbox
- Only read files the provider previously wrote or scaffolded
- Read stderr from the error message to classify the failure
When it happens
Trigger: Reading a path that does not exist in the sandbox, reading a relative path before the project files were written, path containing characters that break the sh command, or the `cat`-equivalent failing for permissions reasons so exitCode !== 0.
Common situations: Dev asks the assistant to read 'src/App.tsx' before setupViteApp scaffolded it; Windows-style backslash paths; reading after a failed file write; directory instead of a file passed to readFile.
Related errors
- Failed to list files
- Unable to read file: ${normalizedPath}
- Failed to write file via shell: ${normalizedPath}
- Failed to write file via command: ${writeResult.stderr}
- Unsupported sandbox type
AI-assisted analysis of firecrawl/open-lovable@69bd93bae7 (2026-08-28).
Data as JSON: /api/errors/2b4e1ec39a5e1675.
Report an issue: GitHub.