Przeglądaj źródła

fix: bunproc stdout / stderr parsing, error handling for bun ResolveMessage (#468)

Wendell Misiedjan 7 miesięcy temu
rodzic
commit
3cfd9d80bc

+ 5 - 6
packages/opencode/src/bun/index.ts

@@ -3,6 +3,7 @@ import { Global } from "../global"
 import { Log } from "../util/log"
 import path from "path"
 import { NamedError } from "../util/error"
+import { readableStreamToText } from "bun"
 
 export namespace BunProc {
   const log = Log.create({ service: "bun" })
@@ -25,11 +26,9 @@ export namespace BunProc {
         BUN_BE_BUN: "1",
       },
     })
-    const code = await result.exited
-    // @ts-ignore
-    const stdout = await result.stdout.text()
-    // @ts-ignore
-    const stderr = await result.stderr.text()
+    const code = await result.exited;
+    const stdout = result.stdout ? typeof result.stdout === "number" ? result.stdout : await readableStreamToText(result.stdout) : undefined
+    const stderr = result.stderr ? typeof result.stderr === "number" ? result.stderr : await readableStreamToText(result.stderr) : undefined
     log.info("done", {
       code,
       stdout,
@@ -65,7 +64,7 @@ export namespace BunProc {
     await BunProc.run(["install", "--registry=https://registry.npmjs.org"], {
       cwd: Global.Path.cache,
     }).catch((e) => {
-      new InstallFailedError(
+      throw new InstallFailedError(
         { pkg, version },
         {
           cause: e,

+ 14 - 1
packages/opencode/src/index.ts

@@ -67,19 +67,32 @@ const cli = yargs(hideBin(process.argv))
 try {
   await cli.parse()
 } catch (e) {
-  const data: Record<string, any> = {}
+  let data: Record<string, any> = {}
   if (e instanceof NamedError) {
     const obj = e.toObject()
     Object.assign(data, {
       ...obj.data,
     })
   }
+  
   if (e instanceof Error) {
     Object.assign(data, {
       name: e.name,
       message: e.message,
       cause: e.cause?.toString(),
     })
+  } 
+  
+  if (e instanceof ResolveMessage) {
+    Object.assign(data, {
+      name: e.name,
+      message: e.message,
+      code: e.code,
+      specifier: e.specifier,
+      referrer: e.referrer,
+      position: e.position,
+      importKind: e.importKind,
+    });
   }
   Log.Default.error("fatal", data)
   const formatted = FormatError(e)