{"record":{"id":"b3af3cabc115647a","repo":"mastra-ai/mastra","slug":"wrapwithwritelock-input-path-is-required","errorCode":null,"errorMessage":"wrapWithWriteLock: input.path is required","messagePattern":"wrapWithWriteLock: input\\.path is required","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/workspace/tools/tools.ts","lineNumber":371,"sourceCode":"      try {\n        output = await tool.execute(input, context);\n      } catch (error) {\n        await hooks.afterToolCall?.({ ...hookContext, output, error });\n        throw error;\n      }\n\n      await hooks.afterToolCall?.({ ...hookContext, output });\n      return output;\n    },\n  };\n}\n\nfunction wrapWithWriteLock(tool: any, writeLock: FileWriteLock): any {\n  return {\n    ...tool,\n    execute: async (input: any, context: any = {}) => {\n      if (!input.path) {\n        throw new Error('wrapWithWriteLock: input.path is required');\n      }\n      return writeLock.withLock(input.path, () => tool.execute(input, context));\n    },\n  };\n}\n\n// ---------------------------------------------------------------------------\n// Factory\n// ---------------------------------------------------------------------------\n\n/**\n * Creates workspace tools that will be auto-injected into agents.\n *\n * @param workspace - The workspace instance to bind tools to\n * @returns Record of workspace tools\n */\nexport async function createWorkspaceTools(\n  workspace: Workspace,","sourceCodeStart":353,"sourceCodeEnd":389,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/workspace/tools/tools.ts#L353-L389","documentation":"The write-lock wrapper serializes mutating tool calls per file path via `writeLock.withLock(input.path, ...)`. If the wrapped tool is invoked without `input.path`, the lock cannot be keyed and the wrapper throws 'wrapWithWriteLock: input.path is required'. This is an internal precondition check, not a domain error class.","triggerScenarios":"Invoking a write-locked tool with input missing the `path` field — e.g. the model emits a malformed tool call with no path, a custom tool is wrapped but its input schema uses a different key (like `filePath` or `file`), or execute is called programmatically with an empty/partial input object.","commonSituations":"Custom tools registered through `addTool` whose input schema names the path property something other than `path`; direct programmatic `execute` calls in tests skipping validation; model hallucinating a tool signature without path.","solutions":["Ensure the tool call input includes a `path` property with a string value","If your tool uses a different input key, rename it to `path` in the tool's input schema or map it before wrapping","Validate tool input against the schema (Zod parse) before calling execute so missing path is caught with a clearer validation message"],"exampleFix":"// before\nawait tool.execute({ filePath: 'a.txt' }, ctx); // throws\n\n// after\nawait tool.execute({ path: 'a.txt' }, ctx);","handlingStrategy":"validation","validationCode":"if (typeof input?.path !== 'string' || input.path.length === 0) {\n  throw new Error('Tool input must include a non-empty string `path`.');\n}","typeGuard":"function hasPath(input) {\n  return typeof input === 'object' && input !== null && typeof input.path === 'string' && input.path.length > 0;\n}","tryCatchPattern":"try {\n  return await tool.execute(input, ctx);\n} catch (err) {\n  if (err instanceof Error && err.message.includes('input.path is required')) {\n    return { error: 'Malformed tool call: missing `path` in input.' };\n  }\n  throw err;\n}","preventionTips":["Define the tool's input schema with a required `path` string field so invalid calls are rejected earlier","Always invoke tools through the framework (schema-validated) rather than calling execute directly with raw objects","Name custom tools' path parameter `path` to match the wrapper's expectation"],"tags":["write-lock","missing-argument","input-validation","workspace-tools"],"backgroundTag":"missing-required-argument","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}