Remove Zod from named errors (#26982)
This commit is contained in:
@@ -382,9 +382,7 @@ export type Part =
|
||||
|
||||
const AssistantErrorSchema = Schema.Union([
|
||||
AuthError.EffectSchema,
|
||||
Schema.Struct({ name: Schema.Literal("UnknownError"), data: Schema.Struct({ message: Schema.String }) }).annotate({
|
||||
identifier: "UnknownError",
|
||||
}),
|
||||
NamedError.Unknown.EffectSchema,
|
||||
OutputLengthError.EffectSchema,
|
||||
AbortedError.EffectSchema,
|
||||
StructuredOutputError.EffectSchema,
|
||||
|
||||
@@ -3,6 +3,7 @@ import { SessionID } from "./schema"
|
||||
import { ModelID, ProviderID } from "../provider/schema"
|
||||
import { NonNegativeInt } from "@opencode-ai/core/schema"
|
||||
import { namedSchemaError } from "@/util/named-schema-error"
|
||||
import { NamedError } from "@opencode-ai/core/util/error"
|
||||
|
||||
export const OutputLengthError = namedSchemaError("MessageOutputLengthError", {})
|
||||
export const AuthError = namedSchemaError("ProviderAuthError", {
|
||||
@@ -10,26 +11,6 @@ export const AuthError = namedSchemaError("ProviderAuthError", {
|
||||
message: Schema.String,
|
||||
})
|
||||
|
||||
const AuthErrorEffect = Schema.Struct({
|
||||
name: Schema.Literal("ProviderAuthError"),
|
||||
data: Schema.Struct({
|
||||
providerID: Schema.String,
|
||||
message: Schema.String,
|
||||
}),
|
||||
})
|
||||
|
||||
const OutputLengthErrorEffect = Schema.Struct({
|
||||
name: Schema.Literal("MessageOutputLengthError"),
|
||||
data: Schema.Struct({}),
|
||||
})
|
||||
|
||||
const UnknownErrorEffect = Schema.Struct({
|
||||
name: Schema.Literal("UnknownError"),
|
||||
data: Schema.Struct({
|
||||
message: Schema.String,
|
||||
}),
|
||||
})
|
||||
|
||||
export const ToolCall = Schema.Struct({
|
||||
state: Schema.Literal("call"),
|
||||
step: Schema.optional(NonNegativeInt),
|
||||
@@ -124,7 +105,9 @@ export const Info = Schema.Struct({
|
||||
created: NonNegativeInt,
|
||||
completed: Schema.optional(NonNegativeInt),
|
||||
}),
|
||||
error: Schema.optional(Schema.Union([AuthErrorEffect, UnknownErrorEffect, OutputLengthErrorEffect])),
|
||||
error: Schema.optional(
|
||||
Schema.Union([AuthError.EffectSchema, NamedError.Unknown.EffectSchema, OutputLengthError.EffectSchema]),
|
||||
),
|
||||
sessionID: SessionID,
|
||||
tool: Schema.Record(
|
||||
Schema.String,
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { NamedError } from "@opencode-ai/core/util/error"
|
||||
import { Cause, Clock, Duration, Effect, Schedule } from "effect"
|
||||
import { MessageV2 } from "./message-v2"
|
||||
import { iife } from "@/util/iife"
|
||||
import { isRecord } from "@/util/record"
|
||||
|
||||
export type Err = ReturnType<NamedError["toObject"]>
|
||||
|
||||
@@ -121,7 +122,7 @@ export function retryable(error: Err, provider: string) {
|
||||
}
|
||||
|
||||
// Check for rate limit patterns in plain text error messages
|
||||
const msg = error.data?.message
|
||||
const msg = isRecord(error.data) ? error.data.message : undefined
|
||||
if (typeof msg === "string") {
|
||||
const lower = msg.toLowerCase()
|
||||
if (
|
||||
@@ -133,7 +134,7 @@ export function retryable(error: Err, provider: string) {
|
||||
}
|
||||
}
|
||||
|
||||
const json = parseJSON(error.data?.message)
|
||||
const json = parseJSON(msg)
|
||||
if (!json || typeof json !== "object") return undefined
|
||||
const code = typeof json.code === "string" ? json.code : ""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user