mastra-ai/mastra · error
Unsupported file type
Error message
Unsupported file type
What it means
readWorkspaceFile only serves regular files; after lstat, anything that is neither a directory nor a regular file (symlinks to non-files, FIFOs, sockets, device nodes) triggers 'Unsupported file type'. The library throws to avoid hanging on special files (e.g. reading a FIFO blocks) or reading meaningless binary device data.
Source
Thrown at mastracode/factory/src/routes/fs.ts:372
workspacePath: workspace,
root: safeRoot,
rootPath: confinedRootPath,
entries: await listRenderedEntries(confinedRootPath),
};
}
export async function readWorkspaceFile(root: string, workspacePath: string, path: string): Promise<WorkspaceFile> {
const safePath = assertRelativePath(path, 'path');
const relativeRoot = safePath.split('/')[0] ?? '';
assertApprovedRenderedRoot(relativeRoot);
const {
workspace,
path: confinedPath,
relativePath,
} = await confinedWorkspaceRelativePath(root, workspacePath, path);
const info = await lstat(confinedPath);
if (info.isDirectory()) throw new Error('Path is a directory');
if (!info.isFile()) throw new Error('Unsupported file type');
const bytesToRead = Math.min(info.size, MAX_TEXT_FILE_BYTES);
const contentBuffer = Buffer.alloc(bytesToRead);
const handle = await open(confinedPath, 'r');
try {
await handle.read(contentBuffer, 0, bytesToRead, 0);
} finally {
await handle.close();
}
try {
const content = TEXT_DECODER.decode(contentBuffer);
return {
workspacePath: workspace,
path: relativePath,
name: relativePath.split('/').pop() ?? relativePath,
size: info.size,
updatedAt: info.mtime.toISOString(),View on GitHub (pinned to 75dd419e61)
Solutions
- Identify the entry's real type (ls -l shows p for FIFO, s for socket) and remove it if it does not belong in the workspace.
- If you need its content, have the producer write to a regular file instead of a pipe/socket.
- Exclude special files from the paths your client requests (filter listing entries by type === 'file').
- Regenerate the workspace/artifacts so the special file is replaced by a normal file.
Example fix
// before: workspace contains a FIFO mkfifo debug.log; GET /fs/file?path=debug.log // → 'Unsupported file type' // after: produce a regular file node script.js > debug.log GET /fs/file?path=debug.log
Defensive patterns
Strategy: try-catch
Validate before calling
import { lstat } from 'node:fs/promises';
async function isRegularFile(p: string): Promise<boolean> {
try {
const info = await lstat(p);
return info.isFile();
} catch {
return false;
}
}
// skip the read when isRegularFile(confinedPath) is false Type guard
function isRegularFileStats(info: { isFile(): boolean; isDirectory(): boolean }): boolean {
return info.isFile() && !info.isDirectory();
} Try / catch
try {
const file = await readWorkspaceFile(root, ws, path);
} catch (e) {
if (e instanceof Error && e.message === 'Unsupported file type') {
// mark entry contentType 'unsupported' / skip it, never retry
return null;
}
throw e;
} Prevention
- Filter listing entries to type === 'file' before requesting content.
- Exclude or clean FIFOs/sockets/device nodes from workspace and artifact directories.
- Never point the read path at pipes or sockets even if a filename suggests text (e.g. debug.log created via mkfifo).
- In sandboxes, mount only regular-file content into browsable roots.
When it happens
Trigger: Calling readWorkspaceFile with a path that resolves to a special filesystem object: a named pipe created by a build tool, a Unix socket in the workspace, a device file bind-mounted into a sandbox, or (via lstat semantics) a non-regular entry exposed by the confinement layer.
Common situations: Workspaces containing build artifacts like .sock pipes or FIFOs; sandboxed session workspaces that expose device nodes; a test fixture accidentally creating a socket where a log file was expected.
Related errors
- Missing required query param: ${label}
- ${label} must be relative
- ${label} escapes workspace
- Path escapes workspace
- Path is a directory
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/74d7a18b185ca62d.
Report an issue: GitHub.