Skip to content

Commit 3406515

Browse files
committed
fix(run): exit with non-zero code on session error in run command
When opencode run encounters a session.error event (e.g., invalid model specified via --model), the process exits with code 0 instead of 1. Root cause: loop() was fired and forgotten (.catch only), so after sdk.session.prompt() returned, execute() exited immediately without waiting for the event loop. Even when loop() ran and set the `error` variable, process.exit(1) was never called. Fix: - Store the loop() promise instead of .catch()-ing it immediately - Await loopDone after the prompt/command call - Call process.exit(1) if error was set during the session Fixes anomalyco#15558
1 parent 98c75be commit 3406515

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

  • packages/opencode/src/cli/cmd

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -582,10 +582,7 @@ export const RunCommand = cmd({
582582
}
583583
await share(sdk, sessionID)
584584

585-
loop().catch((e) => {
586-
console.error(e)
587-
process.exit(1)
588-
})
585+
const loopDone = loop()
589586

590587
if (args.command) {
591588
await sdk.session.command({
@@ -606,6 +603,13 @@ export const RunCommand = cmd({
606603
parts: [...files, { type: "text", text: message }],
607604
})
608605
}
606+
607+
await loopDone.catch((e) => {
608+
console.error(e)
609+
process.exit(1)
610+
})
611+
612+
if (error) process.exit(1)
609613
}
610614

611615
if (args.attach) {

0 commit comments

Comments
 (0)