- {problem}
+ {failureSaid(problem)}
) : answer ? (
diff --git a/app/src/lib/agents/queries.ts b/app/src/lib/agents/queries.ts
index 2d6a1a57ef..aeee8f10fe 100644
--- a/app/src/lib/agents/queries.ts
+++ b/app/src/lib/agents/queries.ts
@@ -13,6 +13,7 @@ import type {
} from "@/lib/api/generated/model";
import { idempotencyKey, organizationId } from "@/lib/api/request";
import { ClientError } from "@/lib/client";
+import { type Failure, failureOf } from "@/lib/load-failure";
export type AgentVisibility = BotVisibility;
@@ -146,10 +147,13 @@ export function agentHandoffQueryOptions(agentId: string) {
});
}
-/** What the server said when it tried the endpoint. */
+/**
+ * What the server said when it tried the endpoint. A refusal is kept whole, so a hold (OpenBot
+ * moving the organization) is drawn calmly rather than as an unreachable address (lib/load-failure.tsx).
+ */
export type ConnectionVerdict =
| { ok: true; events: string[] }
- | { ok: false; reason: string };
+ | { ok: false; reason: Failure };
/** What a person reads when the test itself could not be run. */
const UNTESTED = "The connection could not be tested.";
@@ -179,12 +183,12 @@ export async function testAgentConnection(
{ fallback: UNTESTED },
);
if (verdict.ok) return { ok: true, events: verdict.events };
- return { ok: false, reason: verdict.reason ?? UNTESTED };
+ return { ok: false, reason: { message: verdict.reason ?? UNTESTED } };
} catch (error) {
// A refusal carries the server's sentence (or UNTESTED); a request that never arrived does not.
return {
ok: false,
- reason: error instanceof ClientError ? error.message : UNTESTED,
+ reason: failureOf(error instanceof ClientError ? error : null, UNTESTED),
};
}
}
diff --git a/app/src/lib/apps/mutations.ts b/app/src/lib/apps/mutations.ts
index 22476671d0..8f901ee637 100644
--- a/app/src/lib/apps/mutations.ts
+++ b/app/src/lib/apps/mutations.ts
@@ -10,6 +10,7 @@ import {
import type { AddAppFromDirectory, App } from "@/lib/api/generated/model";
import { idempotencyKey, organizationId } from "@/lib/api/request";
import { ClientError } from "@/lib/client";
+import type { Failure } from "@/lib/load-failure";
import { invalidatePlugins } from "@/lib/plugins/mutations";
import type { SharedUseApproval } from "@/lib/plugins/shared-use";
@@ -69,7 +70,8 @@ export type AddServerByUrlOutcome =
| { added: true; server: App; signIn: boolean }
| {
added: false;
- error: string;
+ /** The refusal kept whole, not as its words, so a hold is drawn calmly (`failureSaid`). */
+ error: Failure;
/** `needs-key` or `not-approved`, when the refusal is one the screen can offer a step for. */
code?: "needs-key" | "not-approved";
/** The app already added at this address, when that is why. */
@@ -103,7 +105,7 @@ export function addServerByUrlMutationOptions(queryClient: QueryClient) {
if (!(thrown instanceof ClientError)) throw thrown;
return {
added: false,
- error: thrown.message,
+ error: thrown,
...(thrown.code === "APP_NEEDS_KEY"
? { code: "needs-key" as const }
: thrown.code === "APP_NOT_APPROVED"
diff --git a/app/src/lib/channels/pending-start.ts b/app/src/lib/channels/pending-start.ts
index ad35dd578e..2fff87a481 100644
--- a/app/src/lib/channels/pending-start.ts
+++ b/app/src/lib/channels/pending-start.ts
@@ -1,3 +1,5 @@
+import type { Failure } from "@/lib/load-failure";
+
/**
* A conversation that has been asked for and does not exist yet.
*
@@ -64,7 +66,11 @@ export function startedChannelFor(id: string): string | null {
*/
export type FailedStart = {
text: string;
- error: string;
+ /**
+ * Why it failed, kept whole rather than as its words: a start refused while OpenBot holds off for
+ * now is said calmly under the box, not as a failure (lib/load-failure.tsx).
+ */
+ error: Failure;
/** The files the message carried, put back on the strip with its words. */
files?: readonly File[];
};
diff --git a/app/src/lib/computers/control.ts b/app/src/lib/computers/control.ts
index 8d867851ea..ef54dbf1f8 100644
--- a/app/src/lib/computers/control.ts
+++ b/app/src/lib/computers/control.ts
@@ -9,6 +9,7 @@ import {
} from "@/lib/api/generated/computers/computers";
import { idempotencyKey, organizationId } from "@/lib/api/request";
import { ClientError } from "@/lib/client";
+import type { Failure } from "@/lib/load-failure";
/**
* Handing control of a Bot's computer to a person, and back.
@@ -151,19 +152,20 @@ export function cancelControl(computerId: string, requestId: string) {
export async function supplySecret(
computerId: string,
text: string,
-): Promise<{ ok: boolean; error?: string }> {
+): Promise<{ ok: boolean; error?: Failure }> {
try {
await supplyComputerSecret(organizationId(), computerId, { text }, once(), {
fallback: "Couldn't type that into the page. Try again.",
});
return { ok: true };
} catch (error) {
+ // The server's refusal kept whole, so a hold is drawn calmly (`failureSaid`).
return {
ok: false,
error:
error instanceof ClientError
- ? error.message
- : "Couldn't reach the Bot's computer. Try again.",
+ ? error
+ : { message: "Couldn't reach the Bot's computer. Try again." },
};
}
}
diff --git a/app/src/lib/connections/connect-app.ts b/app/src/lib/connections/connect-app.ts
index 6270db9a66..24df21c5be 100644
--- a/app/src/lib/connections/connect-app.ts
+++ b/app/src/lib/connections/connect-app.ts
@@ -3,6 +3,7 @@ import { useNavigate } from "@tanstack/react-router";
import { useState } from "react";
import { addCuratedServerMutationOptions } from "@/lib/apps/mutations";
import { appsQueryOptions } from "@/lib/apps/queries";
+import { type Failure, failureOf } from "@/lib/load-failure";
import {
connectAccountMutationOptions,
invalidatePlugins,
@@ -23,7 +24,8 @@ export function useConnectApp() {
const add = useMutation(addCuratedServerMutationOptions(queryClient));
const connect = useMutation(connectAccountMutationOptions("settings"));
const [pending, setPending] = useState
(null);
- const [error, setError] = useState(null);
+ // The refusal itself, not its words: a hold is drawn calmly (`failureSaid`).
+ const [error, setError] = useState(null);
const freshServer = async (key: string) =>
(
@@ -56,7 +58,7 @@ export function useConnectApp() {
queryKey: connectionsQueryOptions().queryKey,
});
} catch (thrown) {
- setError((thrown as Error).message);
+ setError(failureOf(thrown, "Couldn't connect that app."));
} finally {
setPending(null);
}
diff --git a/app/src/lib/copilot/bot-tools.tsx b/app/src/lib/copilot/bot-tools.tsx
index 9b09c06edb..2600534e66 100644
--- a/app/src/lib/copilot/bot-tools.tsx
+++ b/app/src/lib/copilot/bot-tools.tsx
@@ -116,7 +116,7 @@ export function BotTools() {
* saw the roster as it was when the grant arrived, which was before it loaded, so a coworker named
* like an existing one was never flagged.
*/
-function ProposedBotRender(props: {
+export function ProposedBotRender(props: {
args: Partial;
respond?: (result: unknown) => Promise;
result?: string;
diff --git a/app/src/lib/dictation/session.ts b/app/src/lib/dictation/session.ts
index 78f1bb138d..750c7dd631 100644
--- a/app/src/lib/dictation/session.ts
+++ b/app/src/lib/dictation/session.ts
@@ -1,10 +1,12 @@
import { MAX_DICTATION_SECONDS } from "@openbot/shared/dictation";
+import { type Failure, failureOf } from "@/lib/load-failure";
import type { Recording } from "./recording";
export type DictationState = {
phase: "idle" | "requesting" | "recording" | "transcribing" | "error";
seconds: number;
- error?: string;
+ /** Why it stopped, kept whole so a hold is said calmly (lib/load-failure.tsx). */
+ error?: Failure;
canRetry: boolean;
stream?: MediaStream;
};
@@ -66,7 +68,7 @@ export class DictationSession {
const recording = await this.deps.record((error) => {
if (generation !== this.generation) return;
this.cancel();
- this.update({ ...idle, phase: "error", error: error.message });
+ this.update({ ...idle, phase: "error", error });
});
if (generation !== this.generation) {
recording.cancel();
@@ -86,10 +88,12 @@ export class DictationSession {
this.update({
...idle,
phase: "error",
- error:
- error instanceof Error && error.name === "NotAllowedError"
- ? "Microphone access was denied. Allow it in your browser and try again."
- : "Could not start recording. Check your microphone and try again.",
+ error: {
+ message:
+ error instanceof Error && error.name === "NotAllowedError"
+ ? "Microphone access was denied. Allow it in your browser and try again."
+ : "Could not start recording. Check your microphone and try again.",
+ },
});
}
};
@@ -113,7 +117,7 @@ export class DictationSession {
this.update({
...idle,
phase: "error",
- error: "Could not finish recording. Please record again.",
+ error: { message: "Could not finish recording. Please record again." },
});
}
};
@@ -148,10 +152,7 @@ export class DictationSession {
...this.state,
phase: "error",
canRetry: true,
- error:
- error instanceof Error
- ? error.message
- : "Transcription failed. Please retry.",
+ error: failureOf(error, "Transcription failed. Please retry."),
});
}
}
diff --git a/app/src/lib/load-failure.tsx b/app/src/lib/load-failure.tsx
index 7dfd93d4c5..9d2e6cd89a 100644
--- a/app/src/lib/load-failure.tsx
+++ b/app/src/lib/load-failure.tsx
@@ -74,6 +74,43 @@ export function failureSaid(
return error ? loadFailure(error, error.message) : null;
}
+/**
+ * A failure kept to be drawn later through {@link failureSaid}: what a press that failed keeps in its
+ * state, in place of the words alone.
+ *
+ * A press (export the audit log, add someone to a team, create a Bot) used to keep only the error's
+ * words in its state and draw them in red later. The words alone can't say whether
+ * they were a hold's, so a move or a brief outage was drawn as a failure. Kept as one of these, the
+ * server's own refusal is kept whole and `failureSaid` draws it calmly; anything else draws as before.
+ */
+export type Failure = { readonly message: string };
+
+/**
+ * What a press keeps when it fails: the error itself, so `failureSaid` can tell a hold from a
+ * failure and draw the error's own words for a real one, or `otherwise` when what was thrown isn't
+ * an error with words of its own.
+ */
+export function failureOf(thrown: unknown, otherwise: string): Failure {
+ return thrown instanceof Error && thrown.message
+ ? thrown
+ : { message: otherwise };
+}
+
+/**
+ * What a press keeps when it fails and says so in its own sentence: the server's refusal, kept whole,
+ * when it is a hold (to be drawn calmly), and `own` for anything else.
+ */
+export function failureInstead(thrown: unknown, own: string): Failure {
+ return unavailableSaid(thrown) === undefined
+ ? { message: own }
+ : (thrown as ClientError);
+}
+
+/** A toast's type for `error`: a hold is told calmly, as news, and only a failure as an error. */
+export function failureToastType(error: unknown): "error" | "info" {
+ return unavailableSaid(error) === undefined ? "error" : "info";
+}
+
/**
* The same choice as {@link loadFailure}, as plain words, for a place that takes a string (a title,
* a prop typed `string`). A place that draws it should draw a held 503 calmly too.
diff --git a/app/src/lib/models/run-model.ts b/app/src/lib/models/run-model.ts
index debb2f71b4..e5ee4a96b9 100644
--- a/app/src/lib/models/run-model.ts
+++ b/app/src/lib/models/run-model.ts
@@ -2,6 +2,7 @@ import { useMutation, useQuery } from "@tanstack/react-query";
import { useEffect, useRef, useState } from "react";
import { toast } from "@/components/ui/toast";
import type { AgentProfile } from "@/lib/agents/queries";
+import { failureToastType } from "@/lib/load-failure";
import { queryClient } from "@/query-client";
import {
type ModelPick,
@@ -199,7 +200,8 @@ export function useConversationModel(
toast.add({
id: SAVE_FAILED_TOAST,
title: error.message,
- type: "error",
+ // OpenBot holding off for now is news, not a failure (lib/load-failure.tsx).
+ type: failureToastType(error),
});
},
},
diff --git a/app/src/lib/voice/session.ts b/app/src/lib/voice/session.ts
index eceb17bba6..b5981c39a0 100644
--- a/app/src/lib/voice/session.ts
+++ b/app/src/lib/voice/session.ts
@@ -1,4 +1,5 @@
import type { SaveVoiceSessionInput } from "@openbot/shared/voice-session";
+import { type Failure, failureOf } from "@/lib/load-failure";
import { closingOf, openingOf } from "./cut";
import { VOICE_CONTEXT_ITEM_ID, VoiceTranscript } from "./transcript";
import type { ConnectVoice, VoiceConnection, VoiceEvent } from "./types";
@@ -12,7 +13,8 @@ export type VoiceState = {
seconds: number;
transcript: string;
reply: string;
- error?: string;
+ /** Why the call ended, kept whole so a hold is said calmly (lib/load-failure.tsx). */
+ error?: Failure;
stream?: MediaStream;
output?: MediaStream;
};
@@ -101,9 +103,12 @@ export class VoiceSession {
});
};
- private fail(message: string) {
+ private fail(failure: Failure | string) {
this.end();
- this.update({ phase: "error", error: message });
+ this.update({
+ phase: "error",
+ error: typeof failure === "string" ? { message: failure } : failure,
+ });
}
start = async () => {
@@ -131,7 +136,7 @@ export class VoiceSession {
if (current()) this.event(event, generation);
},
onError: (error) => {
- if (current()) this.fail(error.message);
+ if (current()) this.fail(error);
},
onOutput: (output) => {
if (current()) this.update({ output });
@@ -183,11 +188,7 @@ export class VoiceSession {
}, 1000);
} catch (error) {
if (current())
- this.fail(
- error instanceof Error
- ? error.message
- : "Could not start the voice call.",
- );
+ this.fail(failureOf(error, "Could not start the voice call."));
}
};
@@ -208,11 +209,7 @@ export class VoiceSession {
this.connection.send(event);
return true;
} catch (error) {
- this.fail(
- error instanceof Error
- ? error.message
- : "The voice connection was lost.",
- );
+ this.fail(failureOf(error, "The voice connection was lost."));
return false;
}
}
diff --git a/app/src/routes/_authed/_app/channel/new.tsx b/app/src/routes/_authed/_app/channel/new.tsx
index d84f52df59..e54d1fb5ab 100644
--- a/app/src/routes/_authed/_app/channel/new.tsx
+++ b/app/src/routes/_authed/_app/channel/new.tsx
@@ -39,7 +39,12 @@ import {
import { useBotTakesModelChoice } from "@/lib/bot-agents/queries";
import { fallbackBot, useStartChannel } from "@/lib/channels/start";
import { useAttachmentLimits } from "@/lib/deployment/queries";
-import { loadFailure } from "@/lib/load-failure";
+import {
+ type Failure,
+ failureOf,
+ failureSaid,
+ loadFailure,
+} from "@/lib/load-failure";
import { modelCatalogueQueryOptions } from "@/lib/models/queries";
import { useDraftModel } from "@/lib/models/run-model";
import {
@@ -137,7 +142,7 @@ function NewConversation({ composition }: { composition: string }) {
} = useQuery(agentListQueryOptions());
/** Who OpenBot can send to when nobody is in To:. Undefined only when the person has no Bot. */
const fallback = fallbackBot(profiles);
- const [error, setError] = useState(null);
+ const [error, setError] = useState(null);
/** Enter or Send was pressed with no Bot to send to at all. Said until a Bot is chosen. */
const [askedForBot, setAskedForBot] = useState(false);
const pickerInput = useRef(null);
@@ -265,9 +270,7 @@ function NewConversation({ composition }: { composition: string }) {
// The words stay in the box, with the reason under them.
setSent(null);
setError(
- caught instanceof Error
- ? caught.message
- : "Couldn't start the conversation. Try again.",
+ failureOf(caught, "Couldn't start the conversation. Try again."),
);
throw caught;
}
@@ -284,7 +287,7 @@ function NewConversation({ composition }: { composition: string }) {
// A group's messages carry words only, in this first message as in every later one. Files
// held before a second Bot was added are refused out loud and stay on the strip.
if (draft.attachments.length > 0) {
- setError(GROUP_TAKES_NO_FILES);
+ setError({ message: GROUP_TAKES_NO_FILES });
throw new Error(GROUP_TAKES_NO_FILES);
}
setError(null);
@@ -296,11 +299,7 @@ function NewConversation({ composition }: { composition: string }) {
draft.agentId,
);
} catch (caught) {
- setError(
- caught instanceof Error
- ? caught.message
- : "Couldn't start the group. Try again.",
- );
+ setError(failureOf(caught, "Couldn't start the group. Try again."));
throw caught;
}
return;
@@ -325,9 +324,7 @@ function NewConversation({ composition }: { composition: string }) {
// Preserve the unsent draft when channel creation fails.
setSent(null);
setError(
- caught instanceof Error
- ? caught.message
- : "Couldn't start the conversation. Try again.",
+ failureOf(caught, "Couldn't start the conversation. Try again."),
);
throw caught;
}
@@ -452,9 +449,10 @@ function NewConversation({ composition }: { composition: string }) {
});
})
.catch(() => {
- setError(
- "Your Bot was created, but could not be selected. Choose it from the recipient list.",
- );
+ setError({
+ message:
+ "Your Bot was created, but could not be selected. Choose it from the recipient list.",
+ });
});
}}
/>
@@ -522,7 +520,7 @@ function NewConversation({ composition }: { composition: string }) {
notice={
loadError || error ? (
- {loadError ?? error}
+ {loadError ?? failureSaid(error)}
) : askedForBot && recipients.length === 0 ? (
(null);
+ // A refusal is kept whole, not as its words, so a hold is drawn calmly (`failureSaid`).
+ const [notice, setNotice] = useState(null);
const connect = useMutation({
...connectAccountMutationOptions(),
- onError: (thrown: Error) => setNotice(thrown.message),
+ onError: (thrown: Error) => setNotice(thrown),
/*
* A full page navigation, not a fetch. The consent screen is the vendor's own and has to be shown
* to you in your own browser; there is deliberately nothing here that could complete it for you.
@@ -284,9 +285,10 @@ function AppConnectionPage({
? start.authorizationUrl
: null;
if (authorizationUrl === null) {
- setNotice(
- "Couldn't start connecting, so nothing was connected. Try again, or ask an admin if it keeps happening.",
- );
+ setNotice({
+ message:
+ "Couldn't start connecting, so nothing was connected. Try again, or ask an admin if it keeps happening.",
+ });
return;
}
window.location.href = authorizationUrl;
@@ -365,7 +367,7 @@ function AppConnectionPage({
paths.edition === "team" &&
signedIn.isSuccess &&
!isOrganizationAdmin(role);
- const noticeNamesAdmin = notice !== null && /\badmin\b/i.test(notice);
+ const noticeNamesAdmin = notice !== null && /\badmin\b/i.test(notice.message);
const notSetUp =
setup.data !== undefined &&
!setup.data.directoryAvailable &&
@@ -379,9 +381,9 @@ function AppConnectionPage({
member && (noticeNamesAdmin || notSetUp || notOn),
);
/* The server's refusal as it said it, and beside it who the admins are where it names one. */
- const shownNotice =
+ const shownNotice: Failure | null =
notice !== null && noticeNamesAdmin && yourAdmins(admins)
- ? `${notice} ${yourAdmins(admins)}`
+ ? { message: `${notice.message} ${yourAdmins(admins)}` }
: notice;
const removable =
paths.edition === "team" &&
@@ -680,7 +682,7 @@ function AppConnectionPage({
>
{shownNotice ? (
- {shownNotice}
+ {failureSaid(shownNotice)}
) : null}
@@ -801,7 +803,7 @@ function AppConnectionPage({
>
{shownNotice ? (
- {shownNotice}
+ {failureSaid(shownNotice)}
) : null}
@@ -862,9 +864,9 @@ function AppConnectionPage({
* and changed nothing would report that access had been withdrawn when it
* had not, which is the one outcome worse than not offering it.
*/
- setNotice(
- `You can't disconnect here yet. To stop access now, remove OpenBot in your ${app.vendor} account's third-party access settings.`,
- )
+ setNotice({
+ message: `You can't disconnect here yet. To stop access now, remove OpenBot in your ${app.vendor} account's third-party access settings.`,
+ })
}
className="whitespace-nowrap"
variant="destructive"
diff --git a/app/src/routes/_authed/_app/connections.index.tsx b/app/src/routes/_authed/_app/connections.index.tsx
index 77b4f1ab05..7d78c21010 100644
--- a/app/src/routes/_authed/_app/connections.index.tsx
+++ b/app/src/routes/_authed/_app/connections.index.tsx
@@ -73,7 +73,7 @@ import {
identityProvidersQueryOptions,
linkedAccountsQueryOptions,
} from "@/lib/identity/queries";
-import { loadFailure } from "@/lib/load-failure";
+import { failureSaid, loadFailure } from "@/lib/load-failure";
import { keyedLookup } from "@/lib/lookup";
import { useManagePaths } from "@/lib/manage-paths";
import { useReturnToReconnectList } from "@/lib/moves/use-moved-apps";
@@ -612,12 +612,12 @@ function RouteComponent() {
) : null}
{connectApp.error ? (
- {connectApp.error}
+ {failureSaid(connectApp.error)}
) : null}
{press.error ? (
- {press.error}
+ {failureSaid(press.error)}
) : null}
(restored?.error ?? null);
+ const [error, setError] = useState(restored?.error ?? null);
/*
* Whether the person has typed in the box since it was last filled. A start that fails while they
* are writing something else does not overwrite it: it stays stashed, for the next home page.
@@ -230,10 +236,7 @@ function RouteComponent() {
} catch (caught) {
stashFailedStart({
text: draft.text,
- error:
- caught instanceof Error
- ? caught.message
- : "Couldn't start the conversation. Try again.",
+ error: failureOf(caught, "Couldn't start the conversation. Try again."),
files: draft.attachments
.map(heldFileOf)
.filter((file) => file !== undefined),
@@ -336,7 +339,7 @@ function RouteComponent() {
className="mt-2 w-full max-w-2xl text-sm text-destructive"
role="alert"
>
- {error}
+ {failureSaid(error)}
) : failed && agents === undefined ? (
// The composer above is `disabled={!fallback}`, and a failed query does not by
diff --git a/app/src/routes/_authed/admin/boundaries_.$index.tsx b/app/src/routes/_authed/admin/boundaries_.$index.tsx
index 1473743aa0..8a2ce38332 100644
--- a/app/src/routes/_authed/admin/boundaries_.$index.tsx
+++ b/app/src/routes/_authed/admin/boundaries_.$index.tsx
@@ -40,7 +40,7 @@ import {
actionPolicyQueryOptions,
policyDryRunQueryOptions,
} from "@/lib/computers/queries";
-import { failureSaid } from "@/lib/load-failure";
+import { type Failure, failureSaid } from "@/lib/load-failure";
/** How long the rule has to rest before it is replayed, as on Add rule. */
const PREVIEW_DELAY_MS = 400;
@@ -218,7 +218,8 @@ function RuleEditor({ policy, rule }: { policy: ActionPolicy; rule: string }) {
const savePolicy = useMutation(saveActionPolicyMutationOptions(queryClient));
const [draft, setDraft] = useState(rule);
const [written, setWritten] = useState(null);
- const [problem, setProblem] = useState(null);
+ // The error itself, not its words, so a hold is drawn calmly (lib/load-failure.tsx).
+ const [problem, setProblem] = useState(null);
const trimmed = draft.trim();
const changed = trimmed !== rule;
@@ -268,7 +269,7 @@ function RuleEditor({ policy, rule }: { policy: ActionPolicy; rule: string }) {
? { authoring: { source: "english" as const, text: written.text } }
: {}),
},
- { onError: (thrown: Error) => setProblem(thrown.message) },
+ { onError: (thrown: Error) => setProblem(thrown) },
);
};
@@ -321,9 +322,9 @@ function RuleEditor({ policy, rule }: { policy: ActionPolicy; rule: string }) {
{/* A save refused for the reason the preview already gives says nothing twice. */}
- {problem && problem !== preview.error?.message ? (
+ {problem && problem.message !== preview.error?.message ? (
- {problem}
+ {failureSaid(problem)}
) : null}
diff --git a/app/src/routes/_authed/admin/boundaries_.new.tsx b/app/src/routes/_authed/admin/boundaries_.new.tsx
index 762d00c1d7..fb73893439 100644
--- a/app/src/routes/_authed/admin/boundaries_.new.tsx
+++ b/app/src/routes/_authed/admin/boundaries_.new.tsx
@@ -54,6 +54,7 @@ import {
actionPolicyQueryOptions,
policyDryRunQueryOptions,
} from "@/lib/computers/queries";
+import { type Failure, failureSaid } from "@/lib/load-failure";
export const Route = createFileRoute("/_authed/admin/boundaries_/new")({
component: NewRulePage,
@@ -95,7 +96,8 @@ function NewRulePage() {
* replace when the rule is written again; anything else in it is the admin's, and stays.
*/
const [filled, setFilled] = useState({ name: "", description: "" });
- const [problem, setProblem] = useState(null);
+ // The error itself, not its words, so a hold is drawn calmly (lib/load-failure.tsx).
+ const [problem, setProblem] = useState(null);
const policy = stored.data;
const trimmed = rule.trim();
@@ -195,7 +197,7 @@ function NewRulePage() {
: {}),
},
{
- onError: (thrown: Error) => setProblem(thrown.message),
+ onError: (thrown: Error) => setProblem(thrown),
onSuccess: () => void navigate({ to: "/admin/boundaries" }),
},
);
@@ -377,9 +379,9 @@ function NewRulePage() {
* A save refused for the reason the preview already gives under the rule says nothing
* twice: the sentence is on screen, beside the rule it is about.
*/}
- {problem && problem !== preview.error?.message ? (
+ {problem && problem.message !== preview.error?.message ? (
- {problem}
+ {failureSaid(problem)}
) : null}
diff --git a/app/src/routes/_authed/admin/identity-providers.tsx b/app/src/routes/_authed/admin/identity-providers.tsx
index 096ebee7c4..6558da090b 100644
--- a/app/src/routes/_authed/admin/identity-providers.tsx
+++ b/app/src/routes/_authed/admin/identity-providers.tsx
@@ -40,7 +40,7 @@ import {
} from "@/lib/identity-providers/mutations";
import { identityProviderListQueryOptions } from "@/lib/identity-providers/queries";
import { identityProviderWords } from "@/lib/identity-providers/words";
-import { loadFailure, failureSaid } from "@/lib/load-failure";
+import { failureSaid, loadFailure } from "@/lib/load-failure";
import { useCurrentOrganizationId } from "@/lib/organizations/current";
import { ONLY_ORGANIZATION } from "@/lib/organizations/queries";
import { queryClient } from "@/query-client";
@@ -164,7 +164,7 @@ function IdentityProvidersPage() {
{failure ? (
- {failure.message}
+ {failureSaid(failure)}
) : null}
{providers.isPending ? null : providers.error ? (
diff --git a/app/src/routes/_authed/admin/management.tsx b/app/src/routes/_authed/admin/management.tsx
index 56713220d7..45fafdc093 100644
--- a/app/src/routes/_authed/admin/management.tsx
+++ b/app/src/routes/_authed/admin/management.tsx
@@ -43,7 +43,7 @@ import {
} from "@/components/ui/item";
import { Separator } from "@/components/ui/separator";
import { deploymentCapabilitiesQueryOptions } from "@/lib/deployment/queries";
-import { loadFailure } from "@/lib/load-failure";
+import { failureSaid, loadFailure } from "@/lib/load-failure";
import {
helmLines,
MANAGEMENT_SENTENCE,
@@ -167,8 +167,13 @@ export function ManagementPage() {
{cancel.isPending ? "Cancelling…" : "Cancel"}
);
- // The not-entitled refusal is the state itself below, so it isn't said twice.
- const notice = notEntitled ? null : (failure?.message ?? status.lastError);
+ // The not-entitled refusal is the state itself below, so it isn't said twice. A refused press is
+ // drawn through the shared rule, so a hold is said calmly.
+ const notice = notEntitled
+ ? null
+ : failure
+ ? failureSaid(failure)
+ : status.lastError;
return (
diff --git a/app/src/routes/_authed/admin/people.tsx b/app/src/routes/_authed/admin/people.tsx
index 30e40378ec..79d1fc9a39 100644
--- a/app/src/routes/_authed/admin/people.tsx
+++ b/app/src/routes/_authed/admin/people.tsx
@@ -39,7 +39,7 @@ import { Switch } from "@/components/ui/switch";
import { currentUserQueryOptions } from "@/lib/auth/queries";
import { isOrganizationAdmin } from "@/lib/auth/roles";
import { terminateMemberComputersMutationOptions } from "@/lib/enterprise/mutations";
-import { loadFailure, failureSaid } from "@/lib/load-failure";
+import { failureSaid, loadFailure } from "@/lib/load-failure";
import { useCurrentOrganizationId } from "@/lib/organizations/current";
import { useOrganizationChoices } from "@/lib/organizations/queries";
import {
@@ -177,7 +177,7 @@ function PeoplePage() {
>
{failure ? (
- {failure.message}
+ {failureSaid(failure)}
) : null}
{terminate.data ? (
diff --git a/app/src/routes/_authed/admin/playground.tsx b/app/src/routes/_authed/admin/playground.tsx
index 8ae21633f7..0d0bea5e14 100644
--- a/app/src/routes/_authed/admin/playground.tsx
+++ b/app/src/routes/_authed/admin/playground.tsx
@@ -25,6 +25,7 @@ import {
type PlaygroundRecord,
playgroundListQueryOptions,
} from "@/lib/components/queries";
+import { type Failure, failureSaid } from "@/lib/load-failure";
/**
* Browser-authored components are edited as drafts, previewed in the production sandbox renderer,
@@ -120,7 +121,8 @@ function PlaygroundPage() {
const queryClient = useQueryClient();
const { data: components } = useQuery(playgroundListQueryOptions());
const [draft, setDraft] = useState(STARTER);
- const [error, setError] = useState(null);
+ // The error itself, not its words, so a hold is drawn calmly (lib/load-failure.tsx).
+ const [error, setError] = useState(null);
const [notice, setNotice] = useState(null);
const set = (field: keyof Draft) => (value: string) => {
@@ -133,7 +135,7 @@ function PlaygroundPage() {
const sample = validation.ok ? validation.input.sampleArguments : null;
/* Every write here reports into the same banner, so they share one failure handler. */
- const report = { onError: (thrown: Error) => setError(thrown.message) };
+ const report = { onError: (thrown: Error) => setError(thrown) };
const saveDraft = useMutation({
...savePlaygroundDraftMutationOptions(queryClient),
...report,
@@ -154,10 +156,11 @@ function PlaygroundPage() {
const current = validatePlaygroundDraft(draft);
if (!current.ok) {
setNotice(null);
- setError(
- Object.values(current.fields)[0] ??
+ setError({
+ message:
+ Object.values(current.fields)[0] ??
"Fix the JSON fields before saving.",
- );
+ });
return null;
}
return current.input;
@@ -241,7 +244,7 @@ function PlaygroundPage() {
className="border-border border-b bg-destructive/10 px-6 py-2 text-destructive text-sm"
role="alert"
>
- {error}
+ {failureSaid(error)}
) : null}
{notice ? (
diff --git a/app/src/routes/_authed/admin/proactive.tsx b/app/src/routes/_authed/admin/proactive.tsx
index 2b53336bc5..3119e86724 100644
--- a/app/src/routes/_authed/admin/proactive.tsx
+++ b/app/src/routes/_authed/admin/proactive.tsx
@@ -62,7 +62,7 @@ import {
type EnterpriseOverview,
enterpriseOverviewQueryOptions,
} from "@/lib/enterprise/queries";
-import { loadFailure } from "@/lib/load-failure";
+import { failureSaid, loadFailure } from "@/lib/load-failure";
import { queryClient } from "@/query-client";
export const Route = createFileRoute("/_authed/admin/proactive")({
@@ -241,7 +241,7 @@ function CheckInSettings({ data }: { data: EnterpriseOverview }) {
{failure ? (