{"record":{"id":"ae28a3241b4a8557","repo":"mastra-ai/mastra","slug":"path-and-content-are-required","errorCode":null,"errorMessage":"Path and content are required","messagePattern":"Path and content are required","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"packages/server/src/server/handlers/workspace.ts","lineNumber":532,"sourceCode":"  },\n});\n\nexport const WORKSPACE_FS_WRITE_ROUTE = createRoute({\n  method: 'POST',\n  path: '/workspaces/:workspaceId/fs/write',\n  responseType: 'json',\n  pathParamSchema: workspaceIdPathParams,\n  bodySchema: fsWriteBodySchema,\n  responseSchema: fsWriteResponseSchema,\n  summary: 'Write file content',\n  description: 'Writes content to a file at the specified path. Supports base64 encoding for binary files.',\n  tags: ['Workspace'],\n  handler: async ({ mastra, path, content, encoding, recursive, workspaceId }) => {\n    try {\n      requireWorkspaceV1Support();\n\n      if (!path || content === undefined) {\n        throw new HTTPException(400, { message: 'Path and content are required' });\n      }\n\n      const workspace = await getWorkspaceById(mastra, workspaceId);\n      if (!workspace?.filesystem) {\n        throw new HTTPException(404, { message: 'No workspace filesystem configured' });\n      }\n\n      if (workspace.filesystem?.readOnly) {\n        throw new HTTPException(403, { message: 'Workspace is in read-only mode' });\n      }\n\n      const decodedPath = decodeURIComponent(path);\n\n      // Handle base64-encoded content for binary files\n      let fileContent: string | Buffer = content;\n      if (encoding === 'base64') {\n        fileContent = Buffer.from(content, 'base64');\n      }","sourceCodeStart":514,"sourceCodeEnd":550,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/workspace.ts#L514-L550","documentation":"Validation error (HTTP 400) thrown by the workspace file write handler when either the path parameter or the content body is missing. Both are required to create/update a file, so the handler rejects the request up front before touching the filesystem.","triggerScenarios":"POST/PUT to the workspace file write route with no path query parameter, no request body, an empty-string path, or content explicitly undefined — commonly from a misconfigured HTTP client or a serialization step that drops falsy fields.","commonSituations":"JSON.stringify stripping undefined content fields; a form/pipeline step that yields an empty path variable; clients sending form data where the server expects raw string content.","solutions":["Send both the path parameter (URL-encoded) and a non-undefined content body.","Inspect the request layer for undefined fields being dropped; use null-checked defaults before sending.","For intentionally empty files, send an empty string '' as content — only undefined/missing triggers the error."],"exampleFix":"// before\nawait client.write(path); // content undefined\n// after\nawait client.write(path, ''); // or the actual file content","handlingStrategy":"validation","validationCode":"if (typeof path !== 'string' || path.length === 0 || content === undefined) {\n  throw new Error('writeFile requires a non-empty path and defined content (use \"\" for an empty file)');\n}","typeGuard":"function canWrite(path: unknown, content: unknown): path is string {\n  return typeof path === 'string' && path.length > 0 && content !== undefined;\n}","tryCatchPattern":"try {\n  await writeWorkspaceFile({ workspaceId, path, content });\n} catch (e) {\n  if (isHttpException(e, 400) && e.message.includes('Path and content are required')) {\n    throw new Error(`Write aborted: path=${JSON.stringify(path)} content=${typeof content} — check request serialization`);\n  }\n  throw e;\n}","preventionTips":["Never rely on JSON.stringify to carry undefined content — it drops the field.","Use explicit empty strings for intentionally empty files.","Validate path/content at the client boundary before each write."],"tags":["workspace","http-400","validation","missing-parameter","file-write"],"backgroundTag":"missing-required-parameter","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}