Skip to content

Commit 1777d40

Browse files
0xK3vin0xK3vin
authored andcommitted
fix: prevent opencode run crash on malformed tool inputs (anomalyco#13051)
Co-authored-by: 0xK3vin <[email protected]>
1 parent b9f40dd commit 1777d40

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
@@ -406,20 +406,24 @@ export const RunCommand = cmd({
406406

407407
async function execute(sdk: OpencodeClient) {
408408
function tool(part: ToolPart) {
409-
if (part.tool === "bash") return bash(props<typeof BashTool>(part))
410-
if (part.tool === "glob") return glob(props<typeof GlobTool>(part))
411-
if (part.tool === "grep") return grep(props<typeof GrepTool>(part))
412-
if (part.tool === "list") return list(props<typeof ListTool>(part))
413-
if (part.tool === "read") return read(props<typeof ReadTool>(part))
414-
if (part.tool === "write") return write(props<typeof WriteTool>(part))
415-
if (part.tool === "webfetch") return webfetch(props<typeof WebFetchTool>(part))
416-
if (part.tool === "edit") return edit(props<typeof EditTool>(part))
417-
if (part.tool === "codesearch") return codesearch(props<typeof CodeSearchTool>(part))
418-
if (part.tool === "websearch") return websearch(props<typeof WebSearchTool>(part))
419-
if (part.tool === "task") return task(props<typeof TaskTool>(part))
420-
if (part.tool === "todowrite") return todo(props<typeof TodoWriteTool>(part))
421-
if (part.tool === "skill") return skill(props<typeof SkillTool>(part))
422-
return fallback(part)
409+
try {
410+
if (part.tool === "bash") return bash(props<typeof BashTool>(part))
411+
if (part.tool === "glob") return glob(props<typeof GlobTool>(part))
412+
if (part.tool === "grep") return grep(props<typeof GrepTool>(part))
413+
if (part.tool === "list") return list(props<typeof ListTool>(part))
414+
if (part.tool === "read") return read(props<typeof ReadTool>(part))
415+
if (part.tool === "write") return write(props<typeof WriteTool>(part))
416+
if (part.tool === "webfetch") return webfetch(props<typeof WebFetchTool>(part))
417+
if (part.tool === "edit") return edit(props<typeof EditTool>(part))
418+
if (part.tool === "codesearch") return codesearch(props<typeof CodeSearchTool>(part))
419+
if (part.tool === "websearch") return websearch(props<typeof WebSearchTool>(part))
420+
if (part.tool === "task") return task(props<typeof TaskTool>(part))
421+
if (part.tool === "todowrite") return todo(props<typeof TodoWriteTool>(part))
422+
if (part.tool === "skill") return skill(props<typeof SkillTool>(part))
423+
return fallback(part)
424+
} catch {
425+
return fallback(part)
426+
}
423427
}
424428

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

0 commit comments

Comments
 (0)