Skip to content

Commit 7400726

Browse files
authored
fix: show API error messages in remaining CLI and TUI paths (anomalyco#50783)
1 parent 2e4abeb commit 7400726

5 files changed

Lines changed: 17 additions & 18 deletions

File tree

‎packages/cli/src/run/v1.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { Endpoint } from "@opencode/client/effect/service"
22
import { Effect } from "effect"
33
import path from "node:path"
44
import { Standalone } from "../services/standalone"
5+
import { errorMessage } from "../util/error"
56
import { reportRunError, runNonInteractiveWithOptions, type RunCommandInput } from "./run"
67

78
export type V1RunCommandInput = {
@@ -53,7 +54,7 @@ export function runV1Bridge(input: V1RunCommandInput) {
5354
)
5455
}),
5556
),
56-
).catch((error) => reportRunError(input, error instanceof Error ? error.message : String(error)))
57+
).catch((error) => reportRunError(input, errorMessage(error)))
5758
}
5859

5960
function nativeInput(input: V1RunCommandInput, endpoint: Endpoint): RunCommandInput {

‎packages/cli/src/session-target.ts‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { LocationGetOutput, ModelRef, OpenCodeClient, SessionInfo } from "@opencode/client/promise"
22
import { Model } from "@opencode/schema/model"
3+
import { errorMessage } from "./util/error"
34

45
const SESSION_PAGE_LIMIT = 50
56

@@ -24,7 +25,7 @@ export class SessionTargetMutationError extends Error {
2425
override readonly name = "SessionTargetMutationError"
2526

2627
constructor(cause: unknown) {
27-
super(cause instanceof Error ? cause.message : "Session target mutation failed", { cause })
28+
super(errorMessage(cause), { cause })
2829
}
2930
}
3031

@@ -125,11 +126,9 @@ async function selectSession(input: {
125126
if (!selected) return { session: undefined, location }
126127
return {
127128
session: input.fork
128-
? await input.client.session
129-
.fork({ sessionID: selected.id }, ...requestOptions(input.signal))
130-
.catch((error) => {
131-
throw new SessionTargetMutationError(error)
132-
})
129+
? await input.client.session.fork({ sessionID: selected.id }, ...requestOptions(input.signal)).catch((error) => {
130+
throw new SessionTargetMutationError(error)
131+
})
133132
: selected,
134133
}
135134
}
@@ -156,11 +155,7 @@ async function latestSession(
156155
return latestSession(client, location, page.cursor.next, signal)
157156
}
158157

159-
function resolveLocation(
160-
client: OpenCodeClient,
161-
location?: { directory?: string },
162-
signal?: AbortSignal,
163-
) {
158+
function resolveLocation(client: OpenCodeClient, location?: { directory?: string }, signal?: AbortSignal) {
164159
if (!location && !signal) return client.location.get()
165160
if (!location) return client.location.get(undefined, { signal })
166161
return client.location.get({ location }, ...requestOptions(signal))

‎packages/tui/src/component/migration-overlay.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useClient } from "../context/client"
33
import { useTheme } from "../context/theme"
44
import { SplitBorder } from "../ui/border"
55
import { useToast } from "../ui/toast"
6+
import { errorMessage } from "../util/error"
67
import { Spinner } from "./spinner"
78

89
type Progress = { label: string; numerator?: number; denominator?: number }
@@ -30,7 +31,7 @@ export function MigrationOverlay() {
3031
toast.show({
3132
variant: "error",
3233
title: "Data migration failed",
33-
message: error instanceof Error ? error.message : String(error),
34+
message: errorMessage(error),
3435
duration: 10_000,
3536
})
3637
})

‎packages/tui/src/feature-plugins/system/plugins.tsx‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Spinner } from "../../component/spinner"
77
import { usePlugin } from "../../plugin/context"
88
import { DialogSelect, type DialogSelectOption } from "../../ui/dialog-select"
99
import { useDialog } from "../../ui/dialog"
10+
import { errorMessage } from "../../util/error"
1011

1112
const id = "opencode.plugins"
1213

@@ -134,7 +135,7 @@ export function PluginsDialog(props: {
134135
.catch((cause) => {
135136
props.context.ui.toast.show({
136137
variant: "error",
137-
message: cause instanceof Error ? cause.message : String(cause),
138+
message: errorMessage(cause),
138139
})
139140
})
140141
.finally(() => setLocked(false))
@@ -152,7 +153,7 @@ export function PluginsDialog(props: {
152153
.catch((cause) => {
153154
props.context.ui.toast.show({
154155
variant: "error",
155-
message: cause instanceof Error ? cause.message : String(cause),
156+
message: errorMessage(cause),
156157
})
157158
})
158159
.finally(() => setPending((keys) => keys.filter((key) => key !== entry.key)))
@@ -173,7 +174,7 @@ export function PluginsDialog(props: {
173174
.catch((cause) => {
174175
props.context.ui.toast.show({
175176
variant: "error",
176-
message: cause instanceof Error ? cause.message : String(cause),
177+
message: errorMessage(cause),
177178
})
178179
})
179180
.finally(() => setChecking(false))

‎packages/tui/src/mini/runtime.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { SessionMessage } from "@opencode/schema/session-message"
1212
import type { LocationRef } from "@opencode/client/promise"
1313
import type { Config } from "../config"
1414
import { newSessionLocation } from "../config/new-session-location"
15+
import { errorMessage } from "../util/error"
1516
import { loadRunAgents, loadRunCommands, loadRunReferences } from "./catalog.shared"
1617
import {
1718
resolveMiniSettings,
@@ -863,7 +864,7 @@ async function runInteractiveRuntime(input: RunRuntimeInput, deps: RunRuntimeDep
863864
if (signal?.aborted || footer.isClosed) return
864865
const text =
865866
(await state.stream?.then((item) => item.mod).catch(() => undefined))?.formatUnknownError(error) ??
866-
(error instanceof Error ? error.message : String(error))
867+
errorMessage(error)
867868
const commit = {
868869
kind: "error",
869870
text,
@@ -1007,7 +1008,7 @@ async function runInteractiveRuntime(input: RunRuntimeInput, deps: RunRuntimeDep
10071008
})
10081009
const commit = {
10091010
kind: "error",
1010-
text: error instanceof Error ? error.message : String(error),
1011+
text: errorMessage(error),
10111012
phase: "start",
10121013
source: "system",
10131014
messageID: SessionMessage.ID.create(),

0 commit comments

Comments
 (0)