Skip to content

Commit 3bbc3e3

Browse files
authored
feat(opencode): embed backend in oclite binary (#128) (#130)
* feat(opencode): embed backend in oclite binary (#128) * fix(opencode): add process error handlers to oclite entry (#128) * fix(opencode): add comprehensive error handling to oclite entry (#128) - Add process.on('unhandledRejection') handler - Add process.on('uncaughtException') handler - Add main().catch() for fatal errors - All errors logged via Log.Default.error() or console.error Improves error visibility and graceful failure for #128
1 parent a7a9b55 commit 3bbc3e3

2 files changed

Lines changed: 45 additions & 3 deletions

File tree

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,46 @@
11
#!/usr/bin/env bun
2-
/** @jsxImportSource react */
2+
import { Global } from "@/global"
3+
import { Log } from "@/util/log"
4+
import { Instance } from "@/project/instance"
5+
import { InstanceBootstrap } from "@/project/bootstrap"
6+
import { Installation } from "@/installation"
37
import { startInkTUI } from "./index.tsx"
48

5-
startInkTUI()
9+
async function main() {
10+
try {
11+
await Global.init()
12+
await Log.init({
13+
print: process.stdout.isTTY,
14+
dev: Installation.isLocal(),
15+
level: "INFO",
16+
})
17+
18+
process.on("unhandledRejection", (e) => {
19+
Log.Default.error("rejection", {
20+
e: e instanceof Error ? e.message : e,
21+
})
22+
})
23+
24+
process.on("uncaughtException", (e) => {
25+
Log.Default.error("exception", {
26+
e: e instanceof Error ? e.message : e,
27+
})
28+
})
29+
30+
await Instance.provide({
31+
directory: process.cwd(),
32+
init: InstanceBootstrap,
33+
fn: async () => {
34+
await startInkTUI()
35+
},
36+
})
37+
} catch (error) {
38+
console.error("Failed to start oclite:", error)
39+
process.exit(1)
40+
}
41+
}
42+
43+
main().catch((error) => {
44+
console.error("Fatal error:", error)
45+
process.exit(1)
46+
})

‎packages/opencode/src/cli/ink/index.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ import { render } from "ink"
33
import App from "./App"
44

55
export function startInkTUI() {
6-
render(<App />)
6+
const instance = render(<App />)
7+
return instance.waitUntilExit()
78
}

0 commit comments

Comments
 (0)