Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: readable model errors

ogsamrat547c6bdf4533
diff --git a/apps/app/src/app/lib/opencode-session.ts b/apps/app/src/app/lib/opencode-session.ts
index 44b09c54..fe5537fa 100644
--- a/apps/app/src/app/lib/opencode-session.ts
+++ b/apps/app/src/app/lib/opencode-session.ts
@@ -9,7 +9,7 @@
*/
import type { Session } from "@opencode-ai/sdk/v2/client";
import type { Client, ModelRef } from "../types";
-import { unwrap } from "./opencode";
+import { readableErrorMessage, unwrap } from "./opencode";
import { notifyFilesRewound, rewoundFiles } from "./files-rewound";
export type AbortSessionLogContext = {
@@ -263,6 +263,6 @@ function assertNoClientError(result: unknown): void {
? maybe.error.message
: typeof maybe.error === "string"
? maybe.error
- : JSON.stringify(maybe.error);
+ : readableErrorMessage(maybe.error) ?? JSON.stringify(maybe.error);
throw new Error(message || "Unknown error");
}
diff --git a/apps/app/src/app/lib/opencode.ts b/apps/app/src/app/lib/opencode.ts
index 13aab4d5..a2c537f2 100644
--- a/apps/app/src/app/lib/opencode.ts
+++ b/apps/app/src/app/lib/opencode.ts
@@ -354,10 +354,23 @@ export function unwrap<T>(result: FieldsResult<T>): NonNullable<T> {
? result.error.message
: typeof result.error === "string"
? result.error
- : JSON.stringify(result.error);
+ : readableErrorMessage(result.error) ?? JSON.stringify(result.error);
throw new Error(message || "Unknown error");
}
+/**
+ * The text an error answer carries: the app server's `{ code, message }` (a
+ * provider the lock refuses) or the engine's `{ name, data: { message } }`
+ * ("OmniRush models are unavailable: …"), rather than its JSON.
+ */
+export function readableErrorMessage(error: unknown): string | null {
+ if (typeof error !== "object" || error === null) return null;
+ const record = error as { message?: unknown; data?: { message?: unknown } };
+ if (typeof record.message === "string" && record.message.trim()) return record.message;
+ if (typeof record.data === "object" && record.data !== null && typeof record.data.message === "string" && record.data.message.trim()) return record.data.message;
+ return null;
+}
+
export function createClient(baseUrl: string, directory?: string, auth?: OpencodeAuth) {
const headers: Record<string, string> = {};
if (!isDesktopRuntime()) {
diff --git a/apps/app/src/react-app/domains/session/surface/session-surface.tsx b/apps/app/src/react-app/domains/session/surface/session-surface.tsx
index 0b1411a0..e480cf48 100644
--- a/apps/app/src/react-app/domains/session/surface/session-surface.tsx
+++ b/apps/app/src/react-app/domains/session/surface/session-surface.tsx
@@ -170,6 +170,7 @@ import {
} from "./composer-auto-send";
import { useOrgMcpConnections } from "@/react-app/domains/connections/use-org-mcp-connections";
import { buildConnectorToolIdentities } from "@/react-app/domains/connections/connector-tool-identity";
+import { readableErrorMessage } from "@/app/lib/opencode";
const EMPTY_TRANSCRIPT: UIMessage[] = [];
const IDLE_STATUS: SessionStatus = { type: "idle" };
@@ -1010,6 +1011,9 @@ function parseSessionError(thrown: unknown): SessionError {
suggestions: Array.isArray(suggestions) ? suggestions : [],
};
}
+ // The engine's or the app server's own text ("OmniRush models are unavailable: …", a refused provider), not its JSON.
+ const text = readableErrorMessage(parsed);
+ if (text) return { message: text };
} catch {
// Not JSON — fall through to plain message
}
diff --git a/apps/app/tests/readable-error.test.ts b/apps/app/tests/readable-error.test.ts
new file mode 100644
index 00000000..f8db3a84
--- /dev/null
+++ b/apps/app/tests/readable-error.test.ts
@@ -0,0 +1,13 @@
+import { describe, expect, test } from "bun:test";
+
+import { readableErrorMessage } from "../src/app/lib/opencode";
+
+describe("readableErrorMessage", () => {
+ test("the engine's and the app server's own text, not their JSON", () => {
+ expect(readableErrorMessage({ name: "UnknownError", data: { message: "OmniRush models are unavailable: the app's config does not point at the OmniRush gateway (see omnirush_ignored in the engine config). Reinstall or update the app." } }))
+ .toBe("OmniRush models are unavailable: the app's config does not point at the OmniRush gateway (see omnirush_ignored in the engine config). Reinstall or update the app.");
+ expect(readableErrorMessage({ code: "provider_locked", message: "Only OmniRush models are available." })).toBe("Only OmniRush models are available.");
+ expect(readableErrorMessage({ name: "X", data: {} })).toBeNull();
+ expect(readableErrorMessage(null)).toBeNull();
+ });
+});