fix(ui/chat): failures read from the error catalogue

This commit is contained in:
sam committed 2026-11-13 13:41:23 +11:00
1 parent 0d9e2d1cd8
commit f9ac9229d5
7 files changed
+74 -31

No files matched your search

+3 -1
View File
@@ -7,6 +7,8 @@ import { Clock, Mic, Pencil, X } from "@lucide/vue";
import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";
import { Textarea } from "@/components/ui/textarea";
import { errors } from "@/copy/errors";
import { describeError } from "@/lib/api";
import { isExactCommand, replaceToken } from "./commands";
import ChatSlashPalette from "./ChatSlashPalette.vue";
import ChatSuggestions from "./ChatSuggestions.vue";
@@ -75,7 +77,7 @@ async function toggleRecording() {
try {
stream = await navigator.mediaDevices.getUserMedia({ audio: true });
} catch (err) {
recordError.value = `Microphone unavailable: ${(err as Error).message || err}`;
recordError.value = errors.chat.composer.microphoneUnavailable(describeError(err, errors.common.unknown));
return;
}
const chunks: Blob[] = [];
+4 -2
View File
@@ -28,6 +28,8 @@ import {
DialogTitle,
} from "@/components/ui/dialog";
import { Input } from "@/components/ui/input";
import { errors } from "@/copy/errors";
import { describeError } from "@/lib/api";
import ChatSettings from "./ChatSettings.vue";
import {
currentSession,
@@ -68,13 +70,13 @@ async function copyMarkdown(): Promise<void> {
.filter(Boolean)
.join("\n\n");
if (!text) {
toast.error("Nothing to copy");
toast.error(errors.chat.session.nothingToCopy);
return;
}
try {
await navigator.clipboard.writeText(text);
} catch (err) {
toast.error(`Not copied: ${(err as Error).message || "clipboard unavailable"}`);
toast.error(errors.chat.session.copyFailed(describeError(err, errors.chat.session.clipboardUnavailable)));
return;
}
toast.success("Copied as Markdown");
+4 -3
View File
@@ -2,7 +2,8 @@
import { computed, ref } from "vue";
import { Button } from "@/components/ui/button";
import { api } from "@/lib/api";
import { errors } from "@/copy/errors";
import { api, describeError } from "@/lib/api";
import type { ChatUpdate } from "./state";
const props = defineProps<{ update: ChatUpdate }>();
@@ -29,7 +30,7 @@ async function install() {
: "Update finished.";
state.value = "done";
} catch (err) {
result.value = (err as Error).message;
result.value = describeError(err, errors.common.unknown);
state.value = "failed";
}
}
@@ -39,7 +40,7 @@ async function later() {
await api.updateDefer(props.update.snapshot);
state.value = "deferred";
} catch (err) {
result.value = (err as Error).message;
result.value = describeError(err, errors.common.unknown);
state.value = "failed";
}
}
+20 -24
View File
@@ -1,6 +1,7 @@
import { computed, onMounted, onUnmounted, ref, watch, type Ref } from "vue";
import { api } from "@/lib/api";
import { errors } from "@/copy/errors";
import { api, describeError } from "@/lib/api";
import { router } from "@/router";
import { randomUUID } from "@/lib/uuid";
import { channelID } from "./channel";
@@ -195,7 +196,7 @@ export async function answerAsk(answer: string): Promise<boolean> {
try {
await api.chatAnswer(ask.id, answer);
} catch (err) {
askError.value = (err as Error).message || "Could not send the answer";
askError.value = describeError(err, errors.chat.ask.answer);
return false;
}
streamingTurn.value = streamingTurn.value ? { ...streamingTurn.value, ask: undefined } : null;
@@ -348,7 +349,7 @@ async function sendCommand(
text,
page: sentPage(),
});
if (!response.body) throw new Error("the chat stream returned no body");
if (!response.body) throw new Error(errors.chat.stream.noBody);
const reader = response.body.getReader();
const decoder = new TextDecoder();
let buffer = "";
@@ -374,7 +375,7 @@ async function sendCommand(
}
if (done) break;
}
if (!finished) throw new Error("chat stream ended before completion");
if (!finished) throw new Error(errors.chat.stream.endedEarly);
return { reply, session_id: session };
}
@@ -400,8 +401,7 @@ export async function selectSession(id: string): Promise<void> {
if (isCurrentSession(id)) messages.value = transcript;
} catch (err) {
if (isCurrentSession(id))
sessionError.value =
(err as Error).message || "Could not load session messages";
sessionError.value = describeError(err, errors.chat.session.loadMessages);
} finally {
if (isCurrentSession(id)) isLoadingSession.value = false;
}
@@ -437,7 +437,7 @@ async function readTranscript(id: string): Promise<ChatMessage[]> {
text:
failed.status === "cancelled"
? "Stopped before replying."
: failed.error || TURN_FAILED,
: failed.error || errors.chat.turn.failed,
error: failed.status !== "cancelled",
tool_calls: failed.tool_calls || [],
},
@@ -498,7 +498,7 @@ export async function runSessionCommand(command: string): Promise<void> {
await selectSession(result.session_id || currentSession.value);
}
} catch (err) {
statusText.value = (err as Error).message || "Session action failed";
statusText.value = describeError(err, errors.chat.session.command);
}
}
@@ -518,7 +518,7 @@ export async function setModel(model: string): Promise<void> {
// The selector keeps the model the server still has, and the failure is
// shown in the transcript, not only in status text.
selectedModel.value = previous;
sessionError.value = `Model update failed: ${(err as Error).message || err}`;
sessionError.value = errors.chat.session.model(describeError(err, errors.common.unknown));
}
}
@@ -579,7 +579,7 @@ async function loadTasks(): Promise<void> {
taskLoadError.value = "";
} catch (err) {
if (generation !== loadGeneration) return;
taskLoadError.value = (err as Error).message || "Could not load tasks";
taskLoadError.value = describeError(err, errors.chat.tasks.load);
}
renderMenu();
}
@@ -734,7 +734,7 @@ export async function sendMessage(retryOpts?: RetryOptions): Promise<void> {
} catch (err) {
messages.value = [
...messages.value,
{ from: "assistant", text: `Could not check for updates: ${(err as Error).message}` },
{ from: "assistant", text: errors.chat.update.check(describeError(err, errors.common.unknown)) },
];
statusText.value = "Ready";
} finally {
@@ -782,7 +782,7 @@ export async function sendMessage(retryOpts?: RetryOptions): Promise<void> {
{ signal: ctrl.signal },
);
const body = response.body;
if (!body) throw new Error("the chat stream returned no body");
if (!body) throw new Error(errors.chat.stream.noBody);
const reader = body.getReader();
const decoder = new TextDecoder();
@@ -854,7 +854,7 @@ export async function sendMessage(retryOpts?: RetryOptions): Promise<void> {
if (done) break;
}
if (!finished) throw new Error("chat stream ended before completion");
if (!finished) throw new Error(errors.chat.stream.endedEarly);
if (epoch === sessionEpoch) {
// /new opens an empty conversation, so the window clears instead of
@@ -872,7 +872,7 @@ export async function sendMessage(retryOpts?: RetryOptions): Promise<void> {
// The turn succeeded; a failed session-list refresh is reported on its
// own and must not turn into a "retry this turn" error.
await refreshSessions().catch((err) => {
sessionError.value = `Could not refresh the session list: ${(err as Error).message || err}`;
sessionError.value = errors.chat.session.refreshList(describeError(err, errors.common.unknown));
});
} catch (err) {
// A detached turn (conversation switched mid-turn) writes nothing.
@@ -902,17 +902,17 @@ export async function sendMessage(retryOpts?: RetryOptions): Promise<void> {
} else {
streamingTurn.value = {
text: timedOut
? `Archie stopped responding: no activity for ${STREAM_TIMEOUT_MS / 60000} minutes${lastStep(activeTools)}. Try again.`
? errors.chat.stream.timedOut(`${STREAM_TIMEOUT_MS / 60000} minutes${lastStep(activeTools)}`)
: failed instanceof TypeError
? "Archie can't be reached. Check your connection and try again."
: failed.message || TURN_FAILED,
? errors.common.network
: describeError(failed, errors.chat.turn.failed),
tools: activeTools,
isError: true,
turn: turn ? retryChatTurn(turn) : undefined,
isRetry,
reasoning: streamedReasoning,
};
statusText.value = "Error. Retry available.";
statusText.value = errors.chat.turn.failedStatus;
}
} finally {
clearTimeout(timeoutId);
@@ -929,10 +929,6 @@ export async function sendMessage(retryOpts?: RetryOptions): Promise<void> {
}
}
// The server sends a sentence the reader can act on; this is for a failure
// that never reached it, such as a dropped connection.
const TURN_FAILED = "Archie couldn't reply. Try again in a moment.";
function lastStep(tools: ChatToolCall[]): string {
const last = tools.filter((tool) => tool.name || tool.tool).at(-1);
return last ? `, last step: ${last.name || last.tool}` : "";
@@ -942,7 +938,7 @@ export function stopTurn(): void {
statusText.value = "Stopping…";
if (currentSession.value) {
void api.chatCancel(currentSession.value).catch((err) => {
sessionError.value = `Could not stop the turn: ${(err as Error).message || err}`;
sessionError.value = errors.chat.turn.stop(describeError(err, errors.common.unknown));
});
}
abortActiveTurn();
@@ -957,7 +953,7 @@ export function stopTurn(): void {
export function useChat(): void {
onMounted(() => {
refreshSessions().catch((err: Error) => {
statusText.value = err.message || "Chat unavailable";
statusText.value = describeError(err, errors.chat.session.unavailable);
});
});
onUnmounted(() => {
+38
View File
@@ -0,0 +1,38 @@
// Failure copy for the chat panel. Detail values are the caught error's own
// text, passed through describeError at the call site.
export const chat = {
ask: {
answer: "Could not send the answer",
},
composer: {
microphoneUnavailable: (detail: string) => `Microphone unavailable: ${detail}`,
},
session: {
unavailable: "Chat unavailable",
loadMessages: "Could not load session messages",
refreshList: (detail: string) => `Could not refresh the session list: ${detail}`,
command: "Session action failed",
model: (detail: string) => `Model update failed: ${detail}`,
nothingToCopy: "Nothing to copy",
copyFailed: (detail: string) => `Not copied: ${detail}`,
clipboardUnavailable: "clipboard unavailable",
},
tasks: {
load: "Could not load tasks",
},
update: {
check: (detail: string) => `Could not check for updates: ${detail}`,
},
turn: {
// The server sends a sentence the reader can act on; this is for a failure
// that never reached it, such as a dropped connection.
failed: "Archie couldn't reply. Try again in a moment.",
failedStatus: "Error. Retry available.",
stop: (detail: string) => `Could not stop the turn: ${detail}`,
},
stream: {
noBody: "the chat stream returned no body",
endedEarly: "chat stream ended before completion",
timedOut: (detail: string) => `Archie stopped responding: no activity for ${detail}. Try again.`,
},
} as const;
+2
View File
@@ -1,8 +1,10 @@
// Every failure message the dashboard writes itself, by feature. Call sites
// dot-walk it, e.g. errors.chat.composer.microphoneUnavailable, so the copy is
// changed here and nowhere else.
import { chat } from "./chat.ts";
import { common } from "./common.ts";
export const errors = {
chat,
common,
} as const;
+3 -1
View File
@@ -12,7 +12,8 @@ const srcRoot = resolvePath(import.meta.dirname, "../src");
const apiStub =
"data:text/javascript," +
encodeURIComponent(
"export const api = new Proxy({}, { get: (_, p) => globalThis.__archieChatTestApi[p] });",
"export const api = new Proxy({}, { get: (_, p) => globalThis.__archieChatTestApi[p] });" +
"export function describeError(err, fallback) { return err instanceof Error && err.message ? err.message : fallback; }",
);
const routerStub =
"data:text/javascript," +
@@ -26,6 +27,7 @@ register(
export async function resolve(specifier, context, next) {
if (specifier === "@/lib/api") return { url: ${JSON.stringify(apiStub)}, shortCircuit: true };
if (specifier === "@/router") return { url: ${JSON.stringify(routerStub)}, shortCircuit: true };
if (specifier === "@/copy/errors") return { url: SRC + "copy/errors/index.ts", shortCircuit: true };
if (specifier.startsWith("@/")) return { url: SRC + specifier.slice(2) + ".ts", shortCircuit: true };
if ((specifier.startsWith("./") || specifier.startsWith("../")) && !/\\.[a-z0-9]+$/i.test(specifier)) {
return { url: new URL(specifier + ".ts", context.parentURL).href, shortCircuit: true };