Skip to content

Commit 792ab9f

Browse files
author
0xK3vin
committed
fix: prevent opencode run crash on malformed tool inputs
Wrap the tool display dispatch in a try/catch so that when the LLM omits required fields, the CLI falls back to the generic display instead of crashing with a TypeError. Fixes #12978
1 parent c6ec2f4 commit 792ab9f

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

  • packages/opencode/src/cli/cmd

packages/opencode/src/cli/cmd/run.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -390,20 +390,24 @@ export const RunCommand = cmd({
390390

391391
async function execute(sdk: OpencodeClient) {
392392
function tool(part: ToolPart) {
393-
if (part.tool === "bash") return bash(props<typeof BashTool>(part))
394-
if (part.tool === "glob") return glob(props<typeof GlobTool>(part))
395-
if (part.tool === "grep") return grep(props<typeof GrepTool>(part))
396-
if (part.tool === "list") return list(props<typeof ListTool>(part))
397-
if (part.tool === "read") return read(props<typeof ReadTool>(part))
398-
if (part.tool === "write") return write(props<typeof WriteTool>(part))
399-
if (part.tool === "webfetch") return webfetch(props<typeof WebFetchTool>(part))
400-
if (part.tool === "edit") return edit(props<typeof EditTool>(part))
401-
if (part.tool === "codesearch") return codesearch(props<typeof CodeSearchTool>(part))
402-
if (part.tool === "websearch") return websearch(props<typeof WebSearchTool>(part))
403-
if (part.tool === "task") return task(props<typeof TaskTool>(part))
404-
if (part.tool === "todowrite") return todo(props<typeof TodoWriteTool>(part))
405-
if (part.tool === "skill") return skill(props<typeof SkillTool>(part))
406-
return fallback(part)
393+
try {
394+
if (part.tool === "bash") return bash(props<typeof BashTool>(part))
395+
if (part.tool === "glob") return glob(props<typeof GlobTool>(part))
396+
if (part.tool === "grep") return grep(props<typeof GrepTool>(part))
397+
if (part.tool === "list") return list(props<typeof ListTool>(part))
398+
if (part.tool === "read") return read(props<typeof ReadTool>(part))
399+
if (part.tool === "write") return write(props<typeof WriteTool>(part))
400+
if (part.tool === "webfetch") return webfetch(props<typeof WebFetchTool>(part))
401+
if (part.tool === "edit") return edit(props<typeof EditTool>(part))
402+
if (part.tool === "codesearch") return codesearch(props<typeof CodeSearchTool>(part))
403+
if (part.tool === "websearch") return websearch(props<typeof WebSearchTool>(part))
404+
if (part.tool === "task") return task(props<typeof TaskTool>(part))
405+
if (part.tool === "todowrite") return todo(props<typeof TodoWriteTool>(part))
406+
if (part.tool === "skill") return skill(props<typeof SkillTool>(part))
407+
return fallback(part)
408+
} catch {
409+
return fallback(part)
410+
}
407411
}
408412

409413
function emit(type: string, data: Record<string, unknown>) {

0 commit comments

Comments
 (0)