Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(settings): show the real error when a profile save/select/delete fails\n\nEvery failed agent-profile action rendered "[object Object]" instead of the\nbackend's reason, destroying the only diagnostic the user gets on the error\npath of three actions.\n\nCause: `dispatch(thunk).unwrap()` does not reject with an `Error`. For a\n`createAsyncThunk` that threw, Redux Toolkit rethrows its `SerializedError` —\na plain object `{ name, message, stack }` — and for one using\n`rejectWithValue`, the payload, often a bare string. So the guard\n\n err instanceof Error ? err.message : String(err)\n\ntook its `String(err)` branch on exactly the shape it was written to handle,\nand `String({ message: '…' })` is "[object Object]". The guard was defeated by\nthe one case it existed for.\n\nFixed the class, not the three lines. The repo had already solved this twice in\ndomain-specific form — `formatThreadCreateError` (store/threadSlice.ts:115) and\n`formatThreadLoadError` (features/conversations/Conversations.tsx:220), the\nfirst written for the same root cause in #5156. Rather than a fourth copy, this\nadds one general `errorMessage(error, fallback)` in `lib/errorMessage.ts` that\nduck-types `message` instead of testing the prototype, and routes all three\nprofile sites through it.\n\nThe two existing helpers are deliberately left alone: they carry domain\nfallbacks and, in the thread case, an empty-message rule that #5156 depends on.\nConverting them is a follow-up, not part of this fix.\n\nAlso flips the two tests that pinned this defect. Both carried a comment saying\nto invert them rather than delete them when the fix landed (#5886, now merged),\nso a regression re-surfaces in the same place. Added SerializedError-shaped\ncases alongside the `Error` ones, since that is the shape production actually\nproduces and the old tests only ever exercised `Error`.\n\nScope note: 164 files use the same ternary, but the defect only bites where the\nrejection is a non-Error object carrying `message` — the `.unwrap()` boundary.\nOnly the three sites named in the issue are on that boundary, so the diff stops\nthere rather than sweeping files where the guard is correct.\n\nVerified by reading `store/threadSlice.ts:107-127` (the same normalisation, and\nits #5156 rationale) and `lib/theme/chrome.ts` for the sibling call sites; NOT\nexecuted — a fleet-wide no-local-builds rule is in force, so CI is the check.\n\n## Related\nCloses #5900\n

M3gA-Mind456731f19f75
diff --git a/app/src/components/settings/panels/ProfileEditorPage.tsx b/app/src/components/settings/panels/ProfileEditorPage.tsx
index 7a1af92ffe..443fbb12aa 100644
--- a/app/src/components/settings/panels/ProfileEditorPage.tsx
+++ b/app/src/components/settings/panels/ProfileEditorPage.tsx
@@ -15,6 +15,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { LuX } from 'react-icons/lu';
import { useLocation, useNavigate, useParams } from 'react-router-dom';
+import { errorMessage } from '../../../lib/errorMessage';
import { useT } from '../../../lib/i18n/I18nContext';
import { selectAgentProfiles, upsertAgentProfile } from '../../../store/agentProfileSlice';
import { useAppDispatch, useAppSelector } from '../../../store/hooks';
@@ -168,7 +169,12 @@ const ProfileEditorPage = () => {
await dispatch(upsertAgentProfile(profile)).unwrap();
if (mountedRef.current) backToList();
} catch (err) {
- if (mountedRef.current) setError(err instanceof Error ? err.message : String(err));
+ // `.unwrap()` rejects with Redux Toolkit's SerializedError — a plain
+ // object, not an `Error` — so an `instanceof` guard here rendered
+ // "[object Object]" and hid the backend's reason (#5900).
+ if (mountedRef.current) {
+ setError(errorMessage(err, 'Failed to save profile'));
+ }
} finally {
if (mountedRef.current) setSubmitting(false);
}
diff --git a/app/src/components/settings/panels/ProfilesPanel.tsx b/app/src/components/settings/panels/ProfilesPanel.tsx
index 1822122648..0a79edcd78 100644
--- a/app/src/components/settings/panels/ProfilesPanel.tsx
+++ b/app/src/components/settings/panels/ProfilesPanel.tsx
@@ -10,6 +10,7 @@ import { useCallback, useEffect, useState } from 'react';
import { LuPlus } from 'react-icons/lu';
import { useNavigate } from 'react-router-dom';
+import { errorMessage } from '../../../lib/errorMessage';
import { useT } from '../../../lib/i18n/I18nContext';
import {
deleteAgentProfile,
@@ -43,7 +44,9 @@ const ProfilesPanel = () => {
try {
await dispatch(selectAgentProfile(id)).unwrap();
} catch (err) {
- setActionError(err instanceof Error ? err.message : String(err));
+ // See #5900: `.unwrap()` rejects with a SerializedError, so the old
+ // `instanceof` guard rendered "[object Object]" here.
+ setActionError(errorMessage(err, 'Failed to switch profile'));
}
},
[dispatch]
@@ -56,7 +59,7 @@ const ProfilesPanel = () => {
try {
await dispatch(deleteAgentProfile(id)).unwrap();
} catch (err) {
- setActionError(err instanceof Error ? err.message : String(err));
+ setActionError(errorMessage(err, 'Failed to delete profile'));
}
},
[dispatch, t]
diff --git a/app/src/components/settings/panels/__tests__/ProfileEditorPage.payload.test.tsx b/app/src/components/settings/panels/__tests__/ProfileEditorPage.payload.test.tsx
index fffbb334ba..fb428c2dc5 100644
--- a/app/src/components/settings/panels/__tests__/ProfileEditorPage.payload.test.tsx
+++ b/app/src/components/settings/panels/__tests__/ProfileEditorPage.payload.test.tsx
@@ -260,16 +260,13 @@ describe('ProfileEditorPage — failure path', () => {
await waitFor(() => expect(create).not.toBeDisabled());
});
- // BUG (see ~/tinyhuman/bugs/W1-settings-bugs.md): the alert reads
- // "[object Object]", not the message. `dispatch(thunk).unwrap()` rejects with
- // Redux Toolkit's SerializedError — a PLAIN OBJECT, not an `Error` — so the
- // `err instanceof Error ? err.message : String(err)` guard at
- // `ProfileEditorPage.tsx:170` takes the `String(err)` branch and stringifies
- // an object. Every failed profile save shows this.
- //
- // Pinned as CURRENT behaviour so the defect is visible and regression-locked.
- // When it is fixed, change this to assert the message and delete the comment.
- it('renders the failure as [object Object] instead of the message (known defect)', async () => {
+ // Was pinned as a known defect (#5900): the alert read "[object Object]"
+ // because `dispatch(thunk).unwrap()` rejects with Redux Toolkit's
+ // SerializedError — a plain object, not an `Error` — and the old
+ // `err instanceof Error ? err.message : String(err)` guard stringified it.
+ // Fixed by routing through `lib/errorMessage`; the assertion is inverted
+ // rather than deleted, so a regression re-surfaces here.
+ it('renders the failure message, not [object Object]', async () => {
mockUpsert.mockRejectedValueOnce(new Error('backend refused the profile'));
renderAt('/settings/profiles/new');
@@ -277,8 +274,26 @@ describe('ProfileEditorPage — failure path', () => {
fireEvent.click(submit('Create'));
const alert = await screen.findByRole('alert');
- expect(alert).toHaveTextContent('[object Object]');
- expect(alert).not.toHaveTextContent('backend refused the profile');
+ expect(alert).toHaveTextContent('backend refused the profile');
+ expect(alert).not.toHaveTextContent('[object Object]');
+ });
+
+ // The shape that actually reaches this catch in production: a thunk that
+ // threw is rethrown by `.unwrap()` as a SerializedError, never an `Error`.
+ it('renders the message from a SerializedError-shaped rejection', async () => {
+ mockUpsert.mockRejectedValueOnce({
+ name: 'Error',
+ message: 'profile id already taken',
+ stack: 'at …',
+ });
+ renderAt('/settings/profiles/new');
+
+ fireEvent.change(nameField(), { target: { value: 'Doomed' } });
+ fireEvent.click(submit('Create'));
+
+ const alert = await screen.findByRole('alert');
+ expect(alert).toHaveTextContent('profile id already taken');
+ expect(alert).not.toHaveTextContent('[object Object]');
});
it('clears a previous error when the next save succeeds', async () => {
diff --git a/app/src/components/settings/panels/__tests__/ProfilesPanel.actions.test.tsx b/app/src/components/settings/panels/__tests__/ProfilesPanel.actions.test.tsx
index 91eb8d4f78..07528ed2d7 100644
--- a/app/src/components/settings/panels/__tests__/ProfilesPanel.actions.test.tsx
+++ b/app/src/components/settings/panels/__tests__/ProfilesPanel.actions.test.tsx
@@ -5,7 +5,7 @@
* `ProfilesPanel.test.tsx` (sibling) covers the happy paths and the *load*
* error. Neither `setActive` nor `remove` has its failure branch exercised
* anywhere, which is how the `[object Object]` defect at `ProfilesPanel.tsx:46`
- * and `:59` survived — see `~/tinyhuman/bugs/W1-settings-bugs.md`. It also does
+ * and `:59` survived until #5900 fixed it. It also does
* not assert which buttons a built-in or already-active profile may show; those
* are the guards that stop a user deleting a built-in.
*
@@ -88,7 +88,7 @@ describe('ProfilesPanel — action failures', () => {
await waitFor(() => expect(mockSelect).toHaveBeenCalledWith('writer'));
// The panel must say *something* — silence would leave the user believing
// the switch took effect.
- expect(await screen.findByText(/object Object|select blew up/)).toBeInTheDocument();
+ expect(await screen.findByText('select blew up')).toBeInTheDocument();
});
it('shows an error when deleting a profile fails', async () => {
@@ -100,29 +100,41 @@ describe('ProfilesPanel — action failures', () => {
fireEvent.click(within(row('Writer')).getByText('Delete'));
await waitFor(() => expect(mockDelete).toHaveBeenCalledWith('writer'));
- expect(await screen.findByText(/object Object|delete blew up/)).toBeInTheDocument();
+ expect(await screen.findByText('delete blew up')).toBeInTheDocument();
confirmSpy.mockRestore();
});
- // BUG (`~/tinyhuman/bugs/W1-settings-bugs.md` #1): both handlers stringify
- // Redux Toolkit's SerializedError — a plain object, not an `Error` — so
- // `err instanceof Error ? err.message : String(err)` (`ProfilesPanel.tsx:46`
- // and `:59`) yields "[object Object]". The message never reaches the user.
- //
- // Pinned as CURRENT behaviour. When it is fixed, assert the message here and
- // delete this comment — do not delete the test.
- it('renders both action failures as [object Object] (known defect)', async () => {
- const confirmSpy = vi.spyOn(window, 'confirm').mockReturnValue(true);
+ // Was pinned as a known defect (#5900): both handlers stringified Redux
+ // Toolkit's SerializedError — a plain object, not an `Error` — so
+ // `err instanceof Error ? err.message : String(err)` yielded
+ // "[object Object]" and the message never reached the user. Fixed by routing
+ // through `lib/errorMessage`; the assertions are inverted rather than
+ // deleted, so a regression re-surfaces here.
+ it('renders the select failure message, not [object Object]', async () => {
mockSelect.mockRejectedValueOnce(new Error('select blew up'));
renderPanel();
await screen.findByText('Writer');
fireEvent.click(within(row('Writer')).getByText('Set as active'));
- const shown = await screen.findByText('[object Object]');
- expect(shown).toBeInTheDocument();
- expect(screen.queryByText(/select blew up/)).not.toBeInTheDocument();
- confirmSpy.mockRestore();
+ expect(await screen.findByText('select blew up')).toBeInTheDocument();
+ expect(screen.queryByText('[object Object]')).not.toBeInTheDocument();
+ });
+
+ // The production shape: `.unwrap()` rethrows a SerializedError, not an Error.
+ it('renders the message from a SerializedError-shaped rejection', async () => {
+ mockSelect.mockRejectedValueOnce({
+ name: 'Error',
+ message: 'profile is not selectable',
+ stack: 'at …',
+ });
+ renderPanel();
+
+ await screen.findByText('Writer');
+ fireEvent.click(within(row('Writer')).getByText('Set as active'));
+
+ expect(await screen.findByText('profile is not selectable')).toBeInTheDocument();
+ expect(screen.queryByText('[object Object]')).not.toBeInTheDocument();
});
it('clears a previous action error when the next action succeeds', async () => {
@@ -132,10 +144,10 @@ describe('ProfilesPanel — action failures', () => {
await screen.findByText('Writer');
fireEvent.click(within(row('Writer')).getByText('Set as active'));
- expect(await screen.findByText('[object Object]')).toBeInTheDocument();
+ expect(await screen.findByText('first attempt fails')).toBeInTheDocument();
fireEvent.click(within(row('Writer')).getByText('Set as active'));
- await waitFor(() => expect(screen.queryByText('[object Object]')).not.toBeInTheDocument());
+ await waitFor(() => expect(screen.queryByText('first attempt fails')).not.toBeInTheDocument());
});
it('does not delete, and raises no error, when the confirm is dismissed', async () => {
@@ -146,7 +158,7 @@ describe('ProfilesPanel — action failures', () => {
fireEvent.click(within(row('Writer')).getByText('Delete'));
expect(mockDelete).not.toHaveBeenCalled();
- expect(screen.queryByText('[object Object]')).not.toBeInTheDocument();
+ expect(screen.queryByRole('alert')).not.toBeInTheDocument();
confirmSpy.mockRestore();
});
});
diff --git a/app/src/lib/errorMessage.test.ts b/app/src/lib/errorMessage.test.ts
new file mode 100644
index 0000000000..12f85db2fa
--- /dev/null
+++ b/app/src/lib/errorMessage.test.ts
@@ -0,0 +1,63 @@
+import { describe, expect, it } from 'vitest';
+
+import { errorMessage } from './errorMessage';
+
+const FALLBACK = 'Something went wrong';
+
+describe('errorMessage', () => {
+ it('reads the message off a real Error', () => {
+ expect(errorMessage(new Error('boom'), FALLBACK)).toBe('boom');
+ });
+
+ // The case the helper exists for (#5900). `dispatch(thunk).unwrap()` rethrows
+ // Redux Toolkit's SerializedError — a plain object, NOT an Error — so an
+ // `instanceof` guard falls through to `String(value)`, which is
+ // "[object Object]".
+ it('reads the message off a SerializedError-shaped object', () => {
+ const serialized = { name: 'Error', message: 'backend refused the profile', stack: '…' };
+
+ expect(errorMessage(serialized, FALLBACK)).toBe('backend refused the profile');
+ expect(errorMessage(serialized, FALLBACK)).not.toBe('[object Object]');
+ });
+
+ it('accepts a bare string, which is what rejectWithValue often carries', () => {
+ expect(errorMessage('plain failure', FALLBACK)).toBe('plain failure');
+ });
+
+ it('trims surrounding whitespace', () => {
+ expect(errorMessage(new Error(' padded '), FALLBACK)).toBe('padded');
+ expect(errorMessage(' bare ', FALLBACK)).toBe('bare');
+ expect(errorMessage({ message: ' object ' }, FALLBACK)).toBe('object');
+ });
+
+ // An empty message is no more useful than none, and rendering it would put a
+ // blank alert on screen — worse than the fallback, because it reads as "no
+ // error". Same reasoning as `formatThreadCreateError` (threadSlice.ts:117-121).
+ it.each([
+ ['an Error with an empty message', new Error('')],
+ ['an Error with a whitespace message', new Error(' ')],
+ ['an object with an empty message', { message: '' }],
+ ['an object with a whitespace message', { message: ' ' }],
+ ['an empty string', ''],
+ ['a whitespace string', ' '],
+ ])('falls back for %s', (_label, value) => {
+ expect(errorMessage(value, FALLBACK)).toBe(FALLBACK);
+ });
+
+ it.each([
+ ['null', null],
+ ['undefined', undefined],
+ ['a number', 42],
+ ['an object with no message', { code: 500 }],
+ ['an object whose message is not a string', { message: { nested: true } }],
+ ['an array', ['a', 'b']],
+ ])('falls back for %s', (_label, value) => {
+ expect(errorMessage(value, FALLBACK)).toBe(FALLBACK);
+ });
+
+ it('never returns the literal [object Object]', () => {
+ for (const value of [{}, { message: {} }, { code: 1 }, Object.create(null)]) {
+ expect(errorMessage(value, FALLBACK)).toBe(FALLBACK);
+ }
+ });
+});
diff --git a/app/src/lib/errorMessage.ts b/app/src/lib/errorMessage.ts
new file mode 100644
index 0000000000..1ba973e133
--- /dev/null
+++ b/app/src/lib/errorMessage.ts
@@ -0,0 +1,51 @@
+/**
+ * Turn an unknown thrown/rejected value into something worth showing a user.
+ *
+ * The case this exists for: `dispatch(someThunk()).unwrap()` does NOT reject
+ * with an `Error`. For a `createAsyncThunk` that threw, Redux Toolkit rethrows
+ * its `SerializedError` — a plain object `{ name, message, stack }` — and for
+ * one that used `rejectWithValue`, it rethrows the payload, often a bare
+ * string. Neither is an `instanceof Error`.
+ *
+ * So the common guard
+ *
+ * err instanceof Error ? err.message : String(err)
+ *
+ * takes its `String(err)` branch on exactly the shape it was written to
+ * handle, and `String({ message: '…' })` is `"[object Object]"`. The user loses
+ * the only diagnostic the failure path gives them (#5900), and the same shape
+ * caused the "Non-Error promise rejection captured with value" reports in
+ * #5156.
+ *
+ * Read `message` off the value instead of testing its prototype.
+ *
+ * Two existing helpers already solve this for their own domains —
+ * `formatThreadCreateError` (`store/threadSlice.ts`) and `formatThreadLoadError`
+ * (`features/conversations/Conversations.tsx`). Both predate this and carry
+ * domain-specific fallbacks and, in the thread case, an extra empty-message
+ * rule that #5156 depends on; they are deliberately left alone. New call sites
+ * should use this.
+ *
+ * @param error the caught value, of unknown shape
+ * @param fallback shown when nothing usable can be recovered
+ */
+export function errorMessage(error: unknown, fallback: string): string {
+ if (typeof error === 'string' && error.trim().length > 0) return error.trim();
+
+ // An `Error` with an empty message is no more useful than no error at all —
+ // fall through to the fallback rather than rendering a blank alert.
+ if (error instanceof Error && error.message.trim().length > 0) {
+ return error.message.trim();
+ }
+
+ // The SerializedError / rejectWithValue-object case: duck-type `message`
+ // rather than testing the prototype, which is the whole bug.
+ if (error && typeof error === 'object' && 'message' in error) {
+ const message = (error as { message?: unknown }).message;
+ if (typeof message === 'string' && message.trim().length > 0) {
+ return message.trim();
+ }
+ }
+
+ return fallback;
+}