WriteFile sometimes fails with error ERROR The "paths[0]" argument must be of type string. Received undefined
I am not able to reproduce on my machine but the stack trace is hopefully enough to debug.
██████╗ ███████╗███╗ ███╗██╗███╗ ██╗██╗
██╔════╝ ██╔════╝████╗ ████║██║████╗ ██║██║
██║ ███╗█████╗ ██╔████╔██║██║██╔██╗ ██║██║
██║ ██║██╔══╝ ██║╚██╔╝██║██║██║╚██╗██║██║
╚██████╔╝███████╗██║ ╚═╝ ██║██║██║ ╚████║██║
╚═════╝ ╚══════╝╚═╝ ╚═╝╚═╝╚═╝ ╚═══╝╚═╝
Tips for getting started:
1. /help for more information.
2. Ask coding questions, edit code or run commands.
3. Be specific for the best results.
> @packages/cli add tests to the currently empty LoadingIndicator.test.tsx file. use rerender in the tests.
╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✔ ReadManyFiles Will attempt to read and concatenate files using patterns: `packages/cli/**` (within target directory: `/Users/jacobr/git/4/gemini-cli`). Ex… │
│ ReadManyFiles Result (Target Dir: /Users/jacobr/git/4/gemini-cli) │
│ │
│ Successfully read and concatenated content from 95 file(s). │
│ │
│ Processed Files (first 10 shown): │
│ - packages/cli/Dockerfile.sandbox │
│ - packages/cli/README.md │
│ - packages/cli/index.ts │
│ - packages/cli/junit.xml │
│ - packages/cli/package.json │
│ - packages/cli/src/config/config.test.ts │
│ - packages/cli/src/config/config.ts │
│ - packages/cli/src/config/settings.ts │
│ - packages/cli/src/gemini.ts │
│ - packages/cli/src/ui/App.tsx │
│ - ...and 85 more. │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✦ Okay Captain Fun, I will add tests to packages/cli/src/ui/components/LoadingIndicator.test.tsx.
First, I'll read the component's source code to ensure the tests are comprehensive.
╭────────────────────────────────────────────────╮
│ ✔ ReadFile packages/.../LoadingIndicator.tsx │
╰────────────────────────────────────────────────╯
✦ Now I'll write the tests.
ERROR The "paths[0]" argument must be of type string. Received undefined
node:path:1181:7
- Object.resolve (node:path:1181:7)
- makeRelative (packages/server/dist/src/utils/paths.js:92:35)
- WriteFileTool.getDescription (packages/server/dist/src/tools/write-file.js:84:26)
- (packages/cli/dist/src/ui/hooks/useToolScheduler.js:333:31)
- at Array.map (<anonymous>)
- mapToDisplay (packages/cli/dist/src/ui/hooks/useToolScheduler.js:282:31)
- (packages/cli/dist/src/ui/hooks/useGeminiStream.js:46:64)
- updateMemo (node_modules/react-reconciler/cjs/react-reconciler.development.js:7600:19)
- Object.useMemo (node_modules/react-reconciler/cjs/react-reconciler.development.js:8240:16)
- useMemo (node_modules/react/cjs/react.development.js:1650:21)
- ````
This looks like a problem with the file_path parameter for the write_file tool would be undefined if gemini generates a tool call request for write_file but omits the file_path argument, or provides it as undefined.
- The error occurs in
WriteFileTool.getDescription(). This method is used to generate a human-readable description of what the tool will do (e.g., "Write to /path/to/your/file.txt"). - WriteFileTool.getDescription() is called by a function in
useToolScheduler.js(specifically, within an Array.map inside mapToDisplay). This hook is likely responsible for managing and displaying upcoming or in-progress tool calls in the CLI's UI.
So, the sequence is:
- The LLM decides to use the write_file tool.
- It should provide parameters like
{ "file_path": "/path/to/file.txt", "content": "..." }. - If the LLM mistakenly sends parameters like
{ "content": "..." } (missing file_path), then params.file_path would be undefined. - The
useToolSchedulerreceives these parameters and tries to create a display representation for the tool call. - It calls
WriteFileTool.getDescription(params). - Inside
getDescription,makeRelative(params.file_path, ...)is called. Since params.file_path is undefined, makeRelative passes undefined topath.resolve(), leading to the crash.
A fix would handle the symptom by making makeRelative (and thus WriteFileTool.getDescription) more resilient to an undefined file_path. However, the root cause is likely the LLM generating an incomplete tool request.
The useToolScheduler hook, specifically in the mapToDisplay function, calls t.tool.getDescription(t.request.args).
Here's the relevant part of mapToDisplay for a successful, cancelled, awaiting_approval, executing, validating, or scheduled tool call:
// ...
case 'success': // Also applies to 'cancelled', 'awaiting_approval', etc.
return {
callId: t.request.callId,
name: t.tool.displayName,
description: t.tool.getDescription(t.request.args), // <--- This is the call site
resultDisplay: t.response.resultDisplay,
status: mapStatus(t.status),
confirmationDetails: undefined,
renderOutputAsMarkdown: t.tool.isOutputMarkdown,
};
// ...
The t.request.args are the arguments provided by the LLM for the tool call. If the LLM omits file_path from t.request.args for a write_file call, then t.tool.getDescription() (which is WriteFileTool.getDescription()) will receive args where args.file_path is undefined.
So, the chain of events is:
- LLM generates a FunctionCall for write_file but omits file_path in the args.
- The schedule function in useToolScheduler receives this ToolCallRequestInfo (as r).
- It creates a ToolCall object (as t) where
t.request.argsis the (incomplete) arguments from the LLM. - Later,
mapToDisplayis called with this ToolCall object t. mapToDisplaycallst.tool.getDescription(t.request.args).WriteFileTool.getDescription(args)callsmakeRelative(args.file_path, ...).- Since
args.file_pathis undefined, makeRelative passes undefined topath.resolve(), causing the error.
A fix might be to update makeRelative in path.ts with
if (typeof targetPath !== 'string') {
return '.';
}
This might fix the crash but not put the file in the right place???
A fix might be to update makeRelative in path.ts with
if (typeof targetPath !== 'string') { return '.'; }This might fix the crash but not put the file in the right place???
Ultimately this sounds reasonable + making our getDescriptions more resilient is important as well
@scottdensmore if you'd like to tackle this I don't believe Seth has started it
Fixed with https://github.com/google-gemini/gemini-cli/pull/708