fix: show API error messages in remaining CLI and TUI paths (#50783)

This commit is contained in:
Aiden Cline
2026-09-22 20:16:45 -05:00
committed by GitHub
parent 2e4abeb25d
commit 740072694d
5 changed files with 17 additions and 18 deletions
+2 -1
View File
@@ -2,6 +2,7 @@ import type { Endpoint } from "@opencode/client/effect/service"
import { Effect } from "effect"
import path from "node:path"
import { Standalone } from "../services/standalone"
import { errorMessage } from "../util/error"
import { reportRunError, runNonInteractiveWithOptions, type RunCommandInput } from "./run"
export type V1RunCommandInput = {
@@ -53,7 +54,7 @@ export function runV1Bridge(input: V1RunCommandInput) {
)
}),
),
).catch((error) => reportRunError(input, error instanceof Error ? error.message : String(error)))
).catch((error) => reportRunError(input, errorMessage(error)))
}
function nativeInput(input: V1RunCommandInput, endpoint: Endpoint): RunCommandInput {
+6 -11
View File
@@ -1,5 +1,6 @@
import type { LocationGetOutput, ModelRef, OpenCodeClient, SessionInfo } from "@opencode/client/promise"
import { Model } from "@opencode/schema/model"
import { errorMessage } from "./util/error"
const SESSION_PAGE_LIMIT = 50
@@ -24,7 +25,7 @@ export class SessionTargetMutationError extends Error {
override readonly name = "SessionTargetMutationError"
constructor(cause: unknown) {
super(cause instanceof Error ? cause.message : "Session target mutation failed", { cause })
super(errorMessage(cause), { cause })
}
}
@@ -125,11 +126,9 @@ async function selectSession(input: {
if (!selected) return { session: undefined, location }
return {
session: input.fork
? await input.client.session
.fork({ sessionID: selected.id }, ...requestOptions(input.signal))
.catch((error) => {
throw new SessionTargetMutationError(error)
})
? await input.client.session.fork({ sessionID: selected.id }, ...requestOptions(input.signal)).catch((error) => {
throw new SessionTargetMutationError(error)
})
: selected,
}
}
@@ -156,11 +155,7 @@ async function latestSession(
return latestSession(client, location, page.cursor.next, signal)
}
function resolveLocation(
client: OpenCodeClient,
location?: { directory?: string },
signal?: AbortSignal,
) {
function resolveLocation(client: OpenCodeClient, location?: { directory?: string }, signal?: AbortSignal) {
if (!location && !signal) return client.location.get()
if (!location) return client.location.get(undefined, { signal })
return client.location.get({ location }, ...requestOptions(signal))
@@ -3,6 +3,7 @@ import { useClient } from "../context/client"
import { useTheme } from "../context/theme"
import { SplitBorder } from "../ui/border"
import { useToast } from "../ui/toast"
import { errorMessage } from "../util/error"
import { Spinner } from "./spinner"
type Progress = { label: string; numerator?: number; denominator?: number }
@@ -30,7 +31,7 @@ export function MigrationOverlay() {
toast.show({
variant: "error",
title: "Data migration failed",
message: error instanceof Error ? error.message : String(error),
message: errorMessage(error),
duration: 10_000,
})
})
@@ -7,6 +7,7 @@ import { Spinner } from "../../component/spinner"
import { usePlugin } from "../../plugin/context"
import { DialogSelect, type DialogSelectOption } from "../../ui/dialog-select"
import { useDialog } from "../../ui/dialog"
import { errorMessage } from "../../util/error"
const id = "opencode.plugins"
@@ -134,7 +135,7 @@ export function PluginsDialog(props: {
.catch((cause) => {
props.context.ui.toast.show({
variant: "error",
message: cause instanceof Error ? cause.message : String(cause),
message: errorMessage(cause),
})
})
.finally(() => setLocked(false))
@@ -152,7 +153,7 @@ export function PluginsDialog(props: {
.catch((cause) => {
props.context.ui.toast.show({
variant: "error",
message: cause instanceof Error ? cause.message : String(cause),
message: errorMessage(cause),
})
})
.finally(() => setPending((keys) => keys.filter((key) => key !== entry.key)))
@@ -173,7 +174,7 @@ export function PluginsDialog(props: {
.catch((cause) => {
props.context.ui.toast.show({
variant: "error",
message: cause instanceof Error ? cause.message : String(cause),
message: errorMessage(cause),
})
})
.finally(() => setChecking(false))
+3 -2
View File
@@ -12,6 +12,7 @@ import { SessionMessage } from "@opencode/schema/session-message"
import type { LocationRef } from "@opencode/client/promise"
import type { Config } from "../config"
import { newSessionLocation } from "../config/new-session-location"
import { errorMessage } from "../util/error"
import { loadRunAgents, loadRunCommands, loadRunReferences } from "./catalog.shared"
import {
resolveMiniSettings,
@@ -863,7 +864,7 @@ async function runInteractiveRuntime(input: RunRuntimeInput, deps: RunRuntimeDep
if (signal?.aborted || footer.isClosed) return
const text =
(await state.stream?.then((item) => item.mod).catch(() => undefined))?.formatUnknownError(error) ??
(error instanceof Error ? error.message : String(error))
errorMessage(error)
const commit = {
kind: "error",
text,
@@ -1007,7 +1008,7 @@ async function runInteractiveRuntime(input: RunRuntimeInput, deps: RunRuntimeDep
})
const commit = {
kind: "error",
text: error instanceof Error ? error.message : String(error),
text: errorMessage(error),
phase: "start",
source: "system",
messageID: SessionMessage.ID.create(),