{"record":{"id":"74d7a18b185ca62d","repo":"mastra-ai/mastra","slug":"unsupported-file-type","errorCode":null,"errorMessage":"Unsupported file type","messagePattern":"Unsupported file type","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mastracode/factory/src/routes/fs.ts","lineNumber":372,"sourceCode":"    workspacePath: workspace,\n    root: safeRoot,\n    rootPath: confinedRootPath,\n    entries: await listRenderedEntries(confinedRootPath),\n  };\n}\n\nexport async function readWorkspaceFile(root: string, workspacePath: string, path: string): Promise<WorkspaceFile> {\n  const safePath = assertRelativePath(path, 'path');\n  const relativeRoot = safePath.split('/')[0] ?? '';\n  assertApprovedRenderedRoot(relativeRoot);\n  const {\n    workspace,\n    path: confinedPath,\n    relativePath,\n  } = await confinedWorkspaceRelativePath(root, workspacePath, path);\n  const info = await lstat(confinedPath);\n  if (info.isDirectory()) throw new Error('Path is a directory');\n  if (!info.isFile()) throw new Error('Unsupported file type');\n\n  const bytesToRead = Math.min(info.size, MAX_TEXT_FILE_BYTES);\n  const contentBuffer = Buffer.alloc(bytesToRead);\n  const handle = await open(confinedPath, 'r');\n  try {\n    await handle.read(contentBuffer, 0, bytesToRead, 0);\n  } finally {\n    await handle.close();\n  }\n\n  try {\n    const content = TEXT_DECODER.decode(contentBuffer);\n    return {\n      workspacePath: workspace,\n      path: relativePath,\n      name: relativePath.split('/').pop() ?? relativePath,\n      size: info.size,\n      updatedAt: info.mtime.toISOString(),","sourceCodeStart":354,"sourceCodeEnd":390,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/factory/src/routes/fs.ts#L354-L390","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: workspace contains a FIFO\nmkfifo debug.log; GET /fs/file?path=debug.log  // → 'Unsupported file type'\n// after: produce a regular file\nnode script.js > debug.log\nGET /fs/file?path=debug.log","handlingStrategy":"try-catch","validationCode":"import { lstat } from 'node:fs/promises';\nasync function isRegularFile(p: string): Promise<boolean> {\n  try {\n    const info = await lstat(p);\n    return info.isFile();\n  } catch {\n    return false;\n  }\n}\n// skip the read when isRegularFile(confinedPath) is false","typeGuard":"function isRegularFileStats(info: { isFile(): boolean; isDirectory(): boolean }): boolean {\n  return info.isFile() && !info.isDirectory();\n}","tryCatchPattern":"try {\n  const file = await readWorkspaceFile(root, ws, path);\n} catch (e) {\n  if (e instanceof Error && e.message === 'Unsupported file type') {\n    // mark entry contentType 'unsupported' / skip it, never retry\n    return null;\n  }\n  throw e;\n}","preventionTips":["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."],"tags":["filesystem","validation","special-files"],"backgroundTag":"unsupported-file-type","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}