소스 검색

core: prevent TypeError when error handling encounters non-object errors

When API errors like token limit exceeded errors are passed as strings to error checking methods, the 'in' operator would throw a TypeError. This fix adds a type guard to check that the input is an object before attempting to access its properties, allowing proper error classification even when encountering unexpected error formats from providers.
Aiden Cline 10 달 전
부모
커밋
88f12b0822
1개의 변경된 파일1개의 추가작업 그리고 1개의 파일을 삭제
  1. 1 1
      packages/opencode/src/util/error.ts

+ 1 - 1
packages/opencode/src/util/error.ts

@@ -27,7 +27,7 @@ export abstract class NamedError extends Error {
       }
       }
 
 
       static isInstance(input: any): input is InstanceType<typeof result> {
       static isInstance(input: any): input is InstanceType<typeof result> {
-        return "name" in input && input.name === name
+        return typeof input === "object" && "name" in input && input.name === name
       }
       }
 
 
       schema() {
       schema() {