Delete named schema error wrapper (#27066)
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import type { AuthOAuthResult, Hooks } from "@opencode-ai/plugin"
|
import type { AuthOAuthResult, Hooks } from "@opencode-ai/plugin"
|
||||||
import { Auth } from "@/auth"
|
import { Auth } from "@/auth"
|
||||||
import { InstanceState } from "@/effect/instance-state"
|
import { InstanceState } from "@/effect/instance-state"
|
||||||
import { namedSchemaError } from "@/util/named-schema-error"
|
import { NamedError } from "@opencode-ai/core/util/error"
|
||||||
import { optionalOmitUndefined } from "@opencode-ai/core/schema"
|
import { optionalOmitUndefined } from "@opencode-ai/core/schema"
|
||||||
import { Plugin } from "../plugin"
|
import { Plugin } from "../plugin"
|
||||||
import { ProviderID } from "./schema"
|
import { ProviderID } from "./schema"
|
||||||
@@ -64,13 +64,13 @@ export const CallbackInput = Schema.Struct({
|
|||||||
})
|
})
|
||||||
export type CallbackInput = Schema.Schema.Type<typeof CallbackInput>
|
export type CallbackInput = Schema.Schema.Type<typeof CallbackInput>
|
||||||
|
|
||||||
export const OauthMissing = namedSchemaError("ProviderAuthOauthMissing", { providerID: ProviderID })
|
export const OauthMissing = NamedError.create("ProviderAuthOauthMissing", { providerID: ProviderID })
|
||||||
|
|
||||||
export const OauthCodeMissing = namedSchemaError("ProviderAuthOauthCodeMissing", { providerID: ProviderID })
|
export const OauthCodeMissing = NamedError.create("ProviderAuthOauthCodeMissing", { providerID: ProviderID })
|
||||||
|
|
||||||
export const OauthCallbackFailed = namedSchemaError("ProviderAuthOauthCallbackFailed", {})
|
export const OauthCallbackFailed = NamedError.create("ProviderAuthOauthCallbackFailed", {})
|
||||||
|
|
||||||
export const ValidationFailed = namedSchemaError("ProviderAuthValidationFailed", {
|
export const ValidationFailed = NamedError.create("ProviderAuthValidationFailed", {
|
||||||
field: Schema.String,
|
field: Schema.String,
|
||||||
message: Schema.String,
|
message: Schema.String,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import { Auth } from "../auth"
|
|||||||
import { Env } from "../env"
|
import { Env } from "../env"
|
||||||
import { InstallationVersion } from "@opencode-ai/core/installation/version"
|
import { InstallationVersion } from "@opencode-ai/core/installation/version"
|
||||||
import { Flag } from "@opencode-ai/core/flag/flag"
|
import { Flag } from "@opencode-ai/core/flag/flag"
|
||||||
import { namedSchemaError } from "@/util/named-schema-error"
|
import { NamedError } from "@opencode-ai/core/util/error"
|
||||||
import { iife } from "@/util/iife"
|
import { iife } from "@/util/iife"
|
||||||
import { Global } from "@opencode-ai/core/global"
|
import { Global } from "@opencode-ai/core/global"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
@@ -1749,13 +1749,13 @@ export function parseModel(model: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ModelNotFoundError = namedSchemaError("ProviderModelNotFoundError", {
|
export const ModelNotFoundError = NamedError.create("ProviderModelNotFoundError", {
|
||||||
providerID: ProviderID,
|
providerID: ProviderID,
|
||||||
modelID: ModelID,
|
modelID: ModelID,
|
||||||
suggestions: Schema.optional(Schema.Array(Schema.String)),
|
suggestions: Schema.optional(Schema.Array(Schema.String)),
|
||||||
})
|
})
|
||||||
|
|
||||||
export const InitError = namedSchemaError("ProviderInitError", {
|
export const InitError = NamedError.create("ProviderInitError", {
|
||||||
providerID: ProviderID,
|
providerID: ProviderID,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import { Schema } from "effect"
|
||||||
|
import { NamedError } from "@opencode-ai/core/util/error"
|
||||||
|
|
||||||
|
export const OutputLengthError = NamedError.create("MessageOutputLengthError", {})
|
||||||
|
|
||||||
|
export const AuthError = NamedError.create("ProviderAuthError", {
|
||||||
|
providerID: Schema.String,
|
||||||
|
message: Schema.String,
|
||||||
|
})
|
||||||
|
|
||||||
|
export const Shared = [AuthError.EffectSchema, NamedError.Unknown.EffectSchema, OutputLengthError.EffectSchema] as const
|
||||||
|
export const SharedSchema = Schema.Union(Shared)
|
||||||
|
|
||||||
|
export * as MessageError from "./message-error"
|
||||||
@@ -23,8 +23,10 @@ import type { Provider } from "@/provider/provider"
|
|||||||
import { ModelID, ProviderID } from "@/provider/schema"
|
import { ModelID, ProviderID } from "@/provider/schema"
|
||||||
import { Effect, Schema, Types } from "effect"
|
import { Effect, Schema, Types } from "effect"
|
||||||
import { NonNegativeInt } from "@opencode-ai/core/schema"
|
import { NonNegativeInt } from "@opencode-ai/core/schema"
|
||||||
import { namedSchemaError } from "@/util/named-schema-error"
|
|
||||||
import * as EffectLogger from "@opencode-ai/core/effect/logger"
|
import * as EffectLogger from "@opencode-ai/core/effect/logger"
|
||||||
|
import { MessageError } from "./message-error"
|
||||||
|
import { AuthError, OutputLengthError } from "./message-error"
|
||||||
|
export { AuthError, OutputLengthError } from "./message-error"
|
||||||
|
|
||||||
/** Error shape thrown by Bun's fetch() when gzip/br decompression fails mid-stream */
|
/** Error shape thrown by Bun's fetch() when gzip/br decompression fails mid-stream */
|
||||||
interface FetchDecompressionError extends Error {
|
interface FetchDecompressionError extends Error {
|
||||||
@@ -36,17 +38,12 @@ interface FetchDecompressionError extends Error {
|
|||||||
export const SYNTHETIC_ATTACHMENT_PROMPT = "Attached media from tool result:"
|
export const SYNTHETIC_ATTACHMENT_PROMPT = "Attached media from tool result:"
|
||||||
export { isMedia }
|
export { isMedia }
|
||||||
|
|
||||||
export const OutputLengthError = namedSchemaError("MessageOutputLengthError", {})
|
export const AbortedError = NamedError.create("MessageAbortedError", { message: Schema.String })
|
||||||
export const AbortedError = namedSchemaError("MessageAbortedError", { message: Schema.String })
|
export const StructuredOutputError = NamedError.create("StructuredOutputError", {
|
||||||
export const StructuredOutputError = namedSchemaError("StructuredOutputError", {
|
|
||||||
message: Schema.String,
|
message: Schema.String,
|
||||||
retries: NonNegativeInt,
|
retries: NonNegativeInt,
|
||||||
})
|
})
|
||||||
export const AuthError = namedSchemaError("ProviderAuthError", {
|
export const APIError = NamedError.create("APIError", {
|
||||||
providerID: Schema.String,
|
|
||||||
message: Schema.String,
|
|
||||||
})
|
|
||||||
export const APIError = namedSchemaError("APIError", {
|
|
||||||
message: Schema.String,
|
message: Schema.String,
|
||||||
statusCode: Schema.optional(NonNegativeInt),
|
statusCode: Schema.optional(NonNegativeInt),
|
||||||
isRetryable: Schema.Boolean,
|
isRetryable: Schema.Boolean,
|
||||||
@@ -55,7 +52,7 @@ export const APIError = namedSchemaError("APIError", {
|
|||||||
metadata: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
metadata: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
||||||
})
|
})
|
||||||
export type APIError = Schema.Schema.Type<typeof APIError.Schema>
|
export type APIError = Schema.Schema.Type<typeof APIError.Schema>
|
||||||
export const ContextOverflowError = namedSchemaError("ContextOverflowError", {
|
export const ContextOverflowError = NamedError.create("ContextOverflowError", {
|
||||||
message: Schema.String,
|
message: Schema.String,
|
||||||
responseBody: Schema.optional(Schema.String),
|
responseBody: Schema.optional(Schema.String),
|
||||||
})
|
})
|
||||||
@@ -381,9 +378,7 @@ export type Part =
|
|||||||
| CompactionPart
|
| CompactionPart
|
||||||
|
|
||||||
const AssistantErrorSchema = Schema.Union([
|
const AssistantErrorSchema = Schema.Union([
|
||||||
AuthError.EffectSchema,
|
...MessageError.Shared,
|
||||||
NamedError.Unknown.EffectSchema,
|
|
||||||
OutputLengthError.EffectSchema,
|
|
||||||
AbortedError.EffectSchema,
|
AbortedError.EffectSchema,
|
||||||
StructuredOutputError.EffectSchema,
|
StructuredOutputError.EffectSchema,
|
||||||
ContextOverflowError.EffectSchema,
|
ContextOverflowError.EffectSchema,
|
||||||
|
|||||||
@@ -2,14 +2,9 @@ import { Schema } from "effect"
|
|||||||
import { SessionID } from "./schema"
|
import { SessionID } from "./schema"
|
||||||
import { ModelID, ProviderID } from "../provider/schema"
|
import { ModelID, ProviderID } from "../provider/schema"
|
||||||
import { NonNegativeInt } from "@opencode-ai/core/schema"
|
import { NonNegativeInt } from "@opencode-ai/core/schema"
|
||||||
import { namedSchemaError } from "@/util/named-schema-error"
|
import { MessageError } from "./message-error"
|
||||||
import { NamedError } from "@opencode-ai/core/util/error"
|
import { AuthError, OutputLengthError } from "./message-error"
|
||||||
|
export { AuthError, OutputLengthError } from "./message-error"
|
||||||
export const OutputLengthError = namedSchemaError("MessageOutputLengthError", {})
|
|
||||||
export const AuthError = namedSchemaError("ProviderAuthError", {
|
|
||||||
providerID: Schema.String,
|
|
||||||
message: Schema.String,
|
|
||||||
})
|
|
||||||
|
|
||||||
export const ToolCall = Schema.Struct({
|
export const ToolCall = Schema.Struct({
|
||||||
state: Schema.Literal("call"),
|
state: Schema.Literal("call"),
|
||||||
@@ -105,9 +100,7 @@ export const Info = Schema.Struct({
|
|||||||
created: NonNegativeInt,
|
created: NonNegativeInt,
|
||||||
completed: Schema.optional(NonNegativeInt),
|
completed: Schema.optional(NonNegativeInt),
|
||||||
}),
|
}),
|
||||||
error: Schema.optional(
|
error: Schema.optional(MessageError.SharedSchema),
|
||||||
Schema.Union([AuthError.EffectSchema, NamedError.Unknown.EffectSchema, OutputLengthError.EffectSchema]),
|
|
||||||
),
|
|
||||||
sessionID: SessionID,
|
sessionID: SessionID,
|
||||||
tool: Schema.Record(
|
tool: Schema.Record(
|
||||||
Schema.String,
|
Schema.String,
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
import { Schema } from "effect"
|
|
||||||
import { NamedError } from "@opencode-ai/core/util/error"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a Schema-backed NamedError-shaped class.
|
|
||||||
*/
|
|
||||||
export function namedSchemaError<Tag extends string, Fields extends Schema.Struct.Fields>(tag: Tag, fields: Fields) {
|
|
||||||
return NamedError.create(tag, fields)
|
|
||||||
}
|
|
||||||
@@ -2,8 +2,8 @@ import { describe, expect, test } from "bun:test"
|
|||||||
import { Schema } from "effect"
|
import { Schema } from "effect"
|
||||||
import { NamedError } from "@opencode-ai/core/util/error"
|
import { NamedError } from "@opencode-ai/core/util/error"
|
||||||
import { errorData, errorFormat, errorMessage } from "../../src/util/error"
|
import { errorData, errorFormat, errorMessage } from "../../src/util/error"
|
||||||
import { namedSchemaError } from "../../src/util/named-schema-error"
|
|
||||||
import { UI } from "../../src/cli/ui"
|
import { UI } from "../../src/cli/ui"
|
||||||
|
import { MessageError } from "../../src/session/message-error"
|
||||||
|
|
||||||
describe("util.error", () => {
|
describe("util.error", () => {
|
||||||
test("formats native Error instances", () => {
|
test("formats native Error instances", () => {
|
||||||
@@ -53,12 +53,11 @@ describe("util.error", () => {
|
|||||||
expect(String(data.formatted)).toContain("ResolveMessage")
|
expect(String(data.formatted)).toContain("ResolveMessage")
|
||||||
})
|
})
|
||||||
|
|
||||||
test("named schema errors are real NamedError instances", () => {
|
test("schema-backed named errors are real NamedError instances", () => {
|
||||||
const ExampleError = namedSchemaError("ExampleError", { message: Schema.String })
|
const error = new MessageError.AuthError({ providerID: "anthropic", message: "boom" })
|
||||||
const error = new ExampleError({ message: "boom" })
|
|
||||||
|
|
||||||
expect(error).toBeInstanceOf(NamedError)
|
expect(error).toBeInstanceOf(NamedError)
|
||||||
expect(error.toObject()).toEqual({ name: "ExampleError", data: { message: "boom" } })
|
expect(error.toObject()).toEqual({ name: "ProviderAuthError", data: { providerID: "anthropic", message: "boom" } })
|
||||||
})
|
})
|
||||||
|
|
||||||
test("void named errors accept JSON without data", () => {
|
test("void named errors accept JSON without data", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user