Skip to content

Commit 0a7cb20

Browse files
authored
fix(opencode): await run event loop (anomalyco#31389)
1 parent f43209b commit 0a7cb20

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

  • packages/opencode/src/cli/cmd

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -762,10 +762,15 @@ export const RunCommand = effectCmd({
762762

763763
if (!args.interactive) {
764764
const events = await client.event.subscribe()
765-
loop(client, events).catch((e) => {
765+
const completed = loop(client, events).catch((e) => {
766766
console.error(e)
767-
process.exit(1)
767+
process.exitCode = 1
768768
})
769+
async function finish() {
770+
if (args.attach) return
771+
const error = await completed
772+
if (error) process.exitCode = 1
773+
}
769774

770775
if (args.command) {
771776
const result = await client.session.command({
@@ -779,7 +784,9 @@ export const RunCommand = effectCmd({
779784
if (result.error) {
780785
if (!emit("error", { error: result.error })) UI.error(formatRunError(result.error))
781786
process.exitCode = 1
787+
return
782788
}
789+
await finish()
783790
return
784791
}
785792

@@ -794,7 +801,9 @@ export const RunCommand = effectCmd({
794801
if (result.error) {
795802
if (!emit("error", { error: result.error })) UI.error(formatRunError(result.error))
796803
process.exitCode = 1
804+
return
797805
}
806+
await finish()
798807
return
799808
}
800809

0 commit comments

Comments
 (0)