Skip to content

Commit c7d8b0d

Browse files
authored
Delete named schema error wrapper (anomalyco#27066)
1 parent 257fcaf commit c7d8b0d

7 files changed

Lines changed: 38 additions & 46 deletions

File tree

packages/opencode/src/provider/auth.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { AuthOAuthResult, Hooks } from "@opencode-ai/plugin"
22
import { Auth } from "@/auth"
33
import { InstanceState } from "@/effect/instance-state"
4-
import { namedSchemaError } from "@/util/named-schema-error"
4+
import { NamedError } from "@opencode-ai/core/util/error"
55
import { optionalOmitUndefined } from "@opencode-ai/core/schema"
66
import { Plugin } from "../plugin"
77
import { ProviderID } from "./schema"
@@ -64,13 +64,13 @@ export const CallbackInput = Schema.Struct({
6464
})
6565
export type CallbackInput = Schema.Schema.Type<typeof CallbackInput>
6666

67-
export const OauthMissing = namedSchemaError("ProviderAuthOauthMissing", { providerID: ProviderID })
67+
export const OauthMissing = NamedError.create("ProviderAuthOauthMissing", { providerID: ProviderID })
6868

69-
export const OauthCodeMissing = namedSchemaError("ProviderAuthOauthCodeMissing", { providerID: ProviderID })
69+
export const OauthCodeMissing = NamedError.create("ProviderAuthOauthCodeMissing", { providerID: ProviderID })
7070

71-
export const OauthCallbackFailed = namedSchemaError("ProviderAuthOauthCallbackFailed", {})
71+
export const OauthCallbackFailed = NamedError.create("ProviderAuthOauthCallbackFailed", {})
7272

73-
export const ValidationFailed = namedSchemaError("ProviderAuthValidationFailed", {
73+
export const ValidationFailed = NamedError.create("ProviderAuthValidationFailed", {
7474
field: Schema.String,
7575
message: Schema.String,
7676
})

packages/opencode/src/provider/provider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { Auth } from "../auth"
1313
import { Env } from "../env"
1414
import { InstallationVersion } from "@opencode-ai/core/installation/version"
1515
import { Flag } from "@opencode-ai/core/flag/flag"
16-
import { namedSchemaError } from "@/util/named-schema-error"
16+
import { NamedError } from "@opencode-ai/core/util/error"
1717
import { iife } from "@/util/iife"
1818
import { Global } from "@opencode-ai/core/global"
1919
import path from "path"
@@ -1749,13 +1749,13 @@ export function parseModel(model: string) {
17491749
}
17501750
}
17511751

1752-
export const ModelNotFoundError = namedSchemaError("ProviderModelNotFoundError", {
1752+
export const ModelNotFoundError = NamedError.create("ProviderModelNotFoundError", {
17531753
providerID: ProviderID,
17541754
modelID: ModelID,
17551755
suggestions: Schema.optional(Schema.Array(Schema.String)),
17561756
})
17571757

1758-
export const InitError = namedSchemaError("ProviderInitError", {
1758+
export const InitError = NamedError.create("ProviderInitError", {
17591759
providerID: ProviderID,
17601760
})
17611761

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Schema } from "effect"
2+
import { NamedError } from "@opencode-ai/core/util/error"
3+
4+
export const OutputLengthError = NamedError.create("MessageOutputLengthError", {})
5+
6+
export const AuthError = NamedError.create("ProviderAuthError", {
7+
providerID: Schema.String,
8+
message: Schema.String,
9+
})
10+
11+
export const Shared = [AuthError.EffectSchema, NamedError.Unknown.EffectSchema, OutputLengthError.EffectSchema] as const
12+
export const SharedSchema = Schema.Union(Shared)
13+
14+
export * as MessageError from "./message-error"

packages/opencode/src/session/message-v2.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ import type { Provider } from "@/provider/provider"
2323
import { ModelID, ProviderID } from "@/provider/schema"
2424
import { Effect, Schema, Types } from "effect"
2525
import { NonNegativeInt } from "@opencode-ai/core/schema"
26-
import { namedSchemaError } from "@/util/named-schema-error"
2726
import * as EffectLogger from "@opencode-ai/core/effect/logger"
27+
import { MessageError } from "./message-error"
28+
import { AuthError, OutputLengthError } from "./message-error"
29+
export { AuthError, OutputLengthError } from "./message-error"
2830

2931
/** Error shape thrown by Bun's fetch() when gzip/br decompression fails mid-stream */
3032
interface FetchDecompressionError extends Error {
@@ -36,17 +38,12 @@ interface FetchDecompressionError extends Error {
3638
export const SYNTHETIC_ATTACHMENT_PROMPT = "Attached media from tool result:"
3739
export { isMedia }
3840

39-
export const OutputLengthError = namedSchemaError("MessageOutputLengthError", {})
40-
export const AbortedError = namedSchemaError("MessageAbortedError", { message: Schema.String })
41-
export const StructuredOutputError = namedSchemaError("StructuredOutputError", {
41+
export const AbortedError = NamedError.create("MessageAbortedError", { message: Schema.String })
42+
export const StructuredOutputError = NamedError.create("StructuredOutputError", {
4243
message: Schema.String,
4344
retries: NonNegativeInt,
4445
})
45-
export const AuthError = namedSchemaError("ProviderAuthError", {
46-
providerID: Schema.String,
47-
message: Schema.String,
48-
})
49-
export const APIError = namedSchemaError("APIError", {
46+
export const APIError = NamedError.create("APIError", {
5047
message: Schema.String,
5148
statusCode: Schema.optional(NonNegativeInt),
5249
isRetryable: Schema.Boolean,
@@ -55,7 +52,7 @@ export const APIError = namedSchemaError("APIError", {
5552
metadata: Schema.optional(Schema.Record(Schema.String, Schema.String)),
5653
})
5754
export type APIError = Schema.Schema.Type<typeof APIError.Schema>
58-
export const ContextOverflowError = namedSchemaError("ContextOverflowError", {
55+
export const ContextOverflowError = NamedError.create("ContextOverflowError", {
5956
message: Schema.String,
6057
responseBody: Schema.optional(Schema.String),
6158
})
@@ -381,9 +378,7 @@ export type Part =
381378
| CompactionPart
382379

383380
const AssistantErrorSchema = Schema.Union([
384-
AuthError.EffectSchema,
385-
NamedError.Unknown.EffectSchema,
386-
OutputLengthError.EffectSchema,
381+
...MessageError.Shared,
387382
AbortedError.EffectSchema,
388383
StructuredOutputError.EffectSchema,
389384
ContextOverflowError.EffectSchema,

packages/opencode/src/session/message.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@ import { Schema } from "effect"
22
import { SessionID } from "./schema"
33
import { ModelID, ProviderID } from "../provider/schema"
44
import { NonNegativeInt } from "@opencode-ai/core/schema"
5-
import { namedSchemaError } from "@/util/named-schema-error"
6-
import { NamedError } from "@opencode-ai/core/util/error"
7-
8-
export const OutputLengthError = namedSchemaError("MessageOutputLengthError", {})
9-
export const AuthError = namedSchemaError("ProviderAuthError", {
10-
providerID: Schema.String,
11-
message: Schema.String,
12-
})
5+
import { MessageError } from "./message-error"
6+
import { AuthError, OutputLengthError } from "./message-error"
7+
export { AuthError, OutputLengthError } from "./message-error"
138

149
export const ToolCall = Schema.Struct({
1510
state: Schema.Literal("call"),
@@ -105,9 +100,7 @@ export const Info = Schema.Struct({
105100
created: NonNegativeInt,
106101
completed: Schema.optional(NonNegativeInt),
107102
}),
108-
error: Schema.optional(
109-
Schema.Union([AuthError.EffectSchema, NamedError.Unknown.EffectSchema, OutputLengthError.EffectSchema]),
110-
),
103+
error: Schema.optional(MessageError.SharedSchema),
111104
sessionID: SessionID,
112105
tool: Schema.Record(
113106
Schema.String,

packages/opencode/src/util/named-schema-error.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/opencode/test/util/error.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { describe, expect, test } from "bun:test"
22
import { Schema } from "effect"
33
import { NamedError } from "@opencode-ai/core/util/error"
44
import { errorData, errorFormat, errorMessage } from "../../src/util/error"
5-
import { namedSchemaError } from "../../src/util/named-schema-error"
65
import { UI } from "../../src/cli/ui"
6+
import { MessageError } from "../../src/session/message-error"
77

88
describe("util.error", () => {
99
test("formats native Error instances", () => {
@@ -53,12 +53,11 @@ describe("util.error", () => {
5353
expect(String(data.formatted)).toContain("ResolveMessage")
5454
})
5555

56-
test("named schema errors are real NamedError instances", () => {
57-
const ExampleError = namedSchemaError("ExampleError", { message: Schema.String })
58-
const error = new ExampleError({ message: "boom" })
56+
test("schema-backed named errors are real NamedError instances", () => {
57+
const error = new MessageError.AuthError({ providerID: "anthropic", message: "boom" })
5958

6059
expect(error).toBeInstanceOf(NamedError)
61-
expect(error.toObject()).toEqual({ name: "ExampleError", data: { message: "boom" } })
60+
expect(error.toObject()).toEqual({ name: "ProviderAuthError", data: { providerID: "anthropic", message: "boom" } })
6261
})
6362

6463
test("void named errors accept JSON without data", () => {

0 commit comments

Comments
 (0)