Remove Zod from named errors (#26982)

This commit is contained in:
Kit Langton
2026-05-12 09:20:15 -04:00
committed by GitHub
parent 8feb4a31c7
commit 28f38fc871
20 changed files with 197 additions and 245 deletions

View File

@@ -1,5 +1,9 @@
import { describe, expect, test } from "bun:test"
import { Schema } from "effect"
import { NamedError } from "@opencode-ai/core/util/error"
import { errorData, errorFormat, errorMessage } from "../../src/util/error"
import { namedSchemaError } from "../../src/util/named-schema-error"
import { UI } from "../../src/cli/ui"
describe("util.error", () => {
test("formats native Error instances", () => {
@@ -48,4 +52,18 @@ describe("util.error", () => {
expect(data.message).toBe("ResolveMessage: Cannot resolve module")
expect(String(data.formatted)).toContain("ResolveMessage")
})
test("named schema errors are real NamedError instances", () => {
const ExampleError = namedSchemaError("ExampleError", { message: Schema.String })
const error = new ExampleError({ message: "boom" })
expect(error).toBeInstanceOf(NamedError)
expect(error.toObject()).toEqual({ name: "ExampleError", data: { message: "boom" } })
})
test("void named errors accept JSON without data", () => {
const serialized = JSON.parse(JSON.stringify(new UI.CancelledError(undefined).toObject()))
expect(Schema.decodeUnknownOption(UI.CancelledError.Schema)(serialized)._tag).toBe("Some")
})
})