Parcourir la source

redirect uncaught errors to log file

Dax Raad il y a 8 mois
Parent
commit
50469ed750
1 fichiers modifiés avec 12 ajouts et 0 suppressions
  1. 12 0
      packages/opencode/src/index.ts

+ 12 - 0
packages/opencode/src/index.ts

@@ -26,6 +26,18 @@ import { ServeCommand } from "./cli/cmd/serve"
 
 const cancel = new AbortController()
 
+process.on("unhandledRejection", (e) => {
+  Log.Default.error("rejection", {
+    e: e instanceof Error ? e.message : e,
+  })
+})
+
+process.on("uncaughtException", (e) => {
+  Log.Default.error("exception", {
+    e: e instanceof Error ? e.message : e,
+  })
+})
+
 const cli = yargs(hideBin(process.argv))
   .scriptName("opencode")
   .help("help", "show help")