mirror of
https://github.com/anomalyco/opencode.git
synced 2026-06-01 19:05:38 +00:00
Migrate UI cancel error to tagged error (#27112)
This commit is contained in:
@@ -78,8 +78,8 @@ export function FormatError(input: unknown) {
|
|||||||
].join("\n")
|
].join("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
// UICancelledError: void (no data)
|
// UICancelledError: user cancelled an interactive CLI prompt
|
||||||
if (NamedError.hasName(input, "UICancelledError")) {
|
if (isTaggedError(input, "UICancelledError") || NamedError.hasName(input, "UICancelledError")) {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { EOL } from "os"
|
import { EOL } from "os"
|
||||||
import { NamedError } from "@opencode-ai/core/util/error"
|
|
||||||
import { Schema } from "effect"
|
import { Schema } from "effect"
|
||||||
import { logo as glyphs } from "./logo"
|
import { logo as glyphs } from "./logo"
|
||||||
|
|
||||||
@@ -10,7 +9,7 @@ const wordmark = [
|
|||||||
`▀▀▀▀ █▀▀▀ ▀▀▀▀ ▀ ▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀`,
|
`▀▀▀▀ █▀▀▀ ▀▀▀▀ ▀ ▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀`,
|
||||||
]
|
]
|
||||||
|
|
||||||
export const CancelledError = NamedError.create("UICancelledError", Schema.optional(Schema.Void))
|
export class CancelledError extends Schema.TaggedErrorClass<CancelledError>()("UICancelledError", {}) {}
|
||||||
|
|
||||||
export const Style = {
|
export const Style = {
|
||||||
TEXT_HIGHLIGHT: "\x1b[96m",
|
TEXT_HIGHLIGHT: "\x1b[96m",
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { describe, expect, test } from "bun:test"
|
import { describe, expect, test } from "bun:test"
|
||||||
import { AccountTransportError } from "../../src/account/schema"
|
import { AccountTransportError } from "../../src/account/schema"
|
||||||
import { FormatError } from "../../src/cli/error"
|
import { FormatError } from "../../src/cli/error"
|
||||||
|
import { UI } from "../../src/cli/ui"
|
||||||
|
|
||||||
describe("cli.error", () => {
|
describe("cli.error", () => {
|
||||||
test("formats account transport errors clearly", () => {
|
test("formats account transport errors clearly", () => {
|
||||||
@@ -15,4 +16,8 @@ describe("cli.error", () => {
|
|||||||
expect(formatted).toContain("This failed before the server returned an HTTP response.")
|
expect(formatted).toContain("This failed before the server returned an HTTP response.")
|
||||||
expect(formatted).toContain("Check your network, proxy, or VPN configuration and try again.")
|
expect(formatted).toContain("Check your network, proxy, or VPN configuration and try again.")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("formats cancelled UI errors as empty output", () => {
|
||||||
|
expect(FormatError(new UI.CancelledError())).toBe("")
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import { describe, expect, test } from "bun:test"
|
import { describe, expect, test } from "bun:test"
|
||||||
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 { UI } from "../../src/cli/ui"
|
|
||||||
import { MessageError } from "../../src/session/message-error"
|
import { MessageError } from "../../src/session/message-error"
|
||||||
|
|
||||||
describe("util.error", () => {
|
describe("util.error", () => {
|
||||||
@@ -60,9 +58,7 @@ describe("util.error", () => {
|
|||||||
expect(error.toObject()).toEqual({ name: "ProviderAuthError", data: { providerID: "anthropic", message: "boom" } })
|
expect(error.toObject()).toEqual({ name: "ProviderAuthError", data: { providerID: "anthropic", message: "boom" } })
|
||||||
})
|
})
|
||||||
|
|
||||||
test("void named errors accept JSON without data", () => {
|
test("named errors without fields serialize data", () => {
|
||||||
const serialized = JSON.parse(JSON.stringify(new UI.CancelledError(undefined).toObject()))
|
expect(new MessageError.OutputLengthError({}).toObject()).toEqual({ name: "MessageOutputLengthError", data: {} })
|
||||||
|
|
||||||
expect(Schema.decodeUnknownOption(UI.CancelledError.Schema)(serialized)._tag).toBe("Some")
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user