Skip to content

refactor(frontend): give failureText the text of each failed request, and lint the text outside it - #543

Merged
pdevito3 merged 4 commits into
mainfrom
correct/spa-error-text
Nov 22, 2026
Merged

pdevito3 merged 4 commits into
mainfrom
correct/spa-error-text

Conversation

@pdevito3

Copy link
Copy Markdown
Owner

Why

Agents keep writing SPA error text that names a cause the SPA does not know. The past cases are #474, #485, and PR #500, which said "Check your connection" when the Server was down. Each fix patched one screen, so the next screen got it wrong again.

What changed

  • failureText(error) in frontend/src/lib/request-failure.ts is the one owner of the text of a failed request, query, or mutation. An exhaustive Record<SpaTextKind, string> holds the texts of the SPA, and the Server text of a 4xx refusal passes through.
  • Type: Register.defaultError is unknown, so query.error.message does not build.
  • Callers moved: the apiClient toast, QueryError, useServerErrors, StaleVersionAlert (loadFailure: string became loadError: unknown), StartTenantForm, useMembership, the join page and joinViewOf, the workshop edit form, and the weather page.
  • Deleted: serverFaultMessage, noAnswerMessage, timedOutMessage, displayMessage, title, and detail of ProblemDetailsError, handleErrorResponse, and the local fallback texts.
  • Lint messages/failure-text (typed) fails outside the owner on the message of an Error (also destructured, or after a shape check or a cast), the detail or title of a problem, a new Error that the code does not throw or reject, and a root form error with its own text. Each error names failureText.
  • docs/messages.md names the owner, its kinds, and the lint.

Texts that change, each one wrong before:

  • A 401 with a problem body: the token detail became the sign-in text.
  • An error of the app: its developer message, an empty text, or "The save failed. Try again." became "The app has a fault. Reload the page, then try again."
  • Home: "The Server could not load your user." became "Your user did not load. Reload the page."

Scope

The level is architecture plus a type plus a lint. The owner and the type alone do not block error.message after an instanceof narrowing, a hand-made new Error('...') (#500), or a literal text on a root form error. Only the lint sees those. Out of scope: the list pages still show a toast and a QueryError with the same text (#485 class), and the chunk-load texts of page-error.tsx and control-load-error.tsx.

Tradeoffs

One refused kind, not one SPA text per 4xx status. The Server writes the refusal text, and the FSTMSG checks already own it.

Blast Radius

On the next template merge, an app that reads displayMessage, title, detail, the text constants, loadFailure, or query.error.message fails its build. One change is silent: ProblemDetailsError.message is now developer text, and only this lint catches code that shows it. Typed parsing of src/** makes pnpm lint about 60% slower (10 s to 17 s, warm).

Verification

pnpm lint, pnpm build, pnpm test (907 passed), and pnpm test:e2e (370 passed) are green locally. The checks fail on the pre-fix code of ccc196e (#437), c961b2e (#336), 2e37e45^ (before #500), and 3b7a3c7 (main): 27 lint errors and 4 type errors. The output is in the first comment.

…f each failed request

The toast, QueryError, useServerErrors, the stale alert, and the forms and pages
of membership, invites, and weather now show failureText(error). It maps each
kind of failure to one text in an exhaustive Record, and the Server text of a
4xx refusal passes through. The error of a query or a mutation has the type
unknown, so a component cannot show its message.

Delete the old paths: the text constants and displayMessage, title, and detail
of ProblemDetailsError, handleErrorResponse of api-client.ts, and the local
fallback texts of the forms.

The text that the user sees changes only where it was wrong:
- a 401 with a problem body shows the sign-in text, not the token detail
- an error of the app shows "The app has a fault. Reload the page, then try
  again." in place of its developer message, an empty text, or "The save
  failed. Try again."
- the home page says "Your user did not load. Reload the page." in place of
  "The Server could not load your user."
messages/failure-text reads types and fails outside src/lib/request-failure.ts
on the message of an Error, the detail or the title of a problem, a new Error
that the code does not throw, and a root error of a form with a text of its
own. Each error names failureText of @/lib/request-failure.
@pdevito3

Copy link
Copy Markdown
Owner Author

Proof: the checks fail on past mistakes

Each section restores files with git show <rev>:<path> at head 2879decd, then runs pnpm exec eslint and pnpm exec tsc -b of this branch. The commits:

### ccc196ef: frontend/src/domain/invites/components/claim-invite-form.tsx frontend/src/domain/invites/components/invite-user-dialog.tsx
$ pnpm exec eslint <files>
src/domain/invites/components/claim-invite-form.tsx:37:48 messages/failure-text: Do not make an error to carry a text to the screen.
src/domain/invites/components/invite-user-dialog.tsx:70:48 messages/failure-text: Do not make an error to carry a text to the screen.
$ pnpm exec tsc -b (errors in these files)
(none)
### c961b2e9: frontend/src/domain/membership/components/start-tenant-form.tsx
$ pnpm exec eslint <files>
src/domain/membership/components/start-tenant-form.tsx:43:47 messages/failure-text: The root error of a form shows a failed submit.
src/domain/membership/components/start-tenant-form.tsx:55:64 messages/failure-text: The root error of a form shows a failed submit.
$ pnpm exec tsc -b (errors in these files)
src/domain/membership/components/start-tenant-form.tsx(55,70): error TS2339: Property 'displayMessage' does not exist on type 'ProblemDetailsError'.
### 2e37e453^: frontend/src/lib/api-client.ts frontend/src/lib/problem-details.ts
$ pnpm exec eslint <files>
src/lib/api-client.ts:52:7 messages/failure-text: Do not show the detail or the title of a problem.
src/lib/api-client.ts:53:12 messages/failure-text: Do not show the detail or the title of a problem.
src/lib/api-client.ts:56:10 messages/failure-text: Do not show the detail or the title of a problem.
src/lib/api-client.ts:79:13 messages/failure-text: Do not show the message of an error.
src/lib/api-client.ts:81:12 messages/failure-text: Do not make an error to carry a text to the screen.
src/lib/api-client.ts:84:10 messages/failure-text: Do not make an error to carry a text to the screen.
src/lib/api-client.ts:84:20 messages/failure-text: Do not show the message of an error.
src/lib/api-client.ts:128:13 messages/failure-text: Do not show the message of an error.
src/lib/problem-details.ts:26:11 messages/failure-text: Do not show the detail or the title of a problem.
src/lib/problem-details.ts:26:36 messages/failure-text: Do not show the detail or the title of a problem.
src/lib/problem-details.ts:41:12 messages/failure-text: Do not show the detail or the title of a problem.
src/lib/problem-details.ts:45:12 messages/failure-text: Do not show the detail or the title of a problem.
src/lib/problem-details.ts:56:12 messages/failure-text: Do not show the detail or the title of a problem.
src/lib/problem-details.ts:56:42 messages/failure-text: Do not show the detail or the title of a problem.
$ pnpm exec tsc -b (errors in these files)
(none)
### 3b7a3c71: frontend/src/domain/membership/components/start-tenant-form.tsx frontend/src/routes/(examples)/weather.tsx frontend/src/hooks/use-server-errors.ts frontend/src/components/query-error.tsx frontend/src/examples/workshops/compone
$ pnpm exec eslint <files>
src/components/query-error.tsx:14:31 messages/failure-text: Do not show the message of an error.
src/domain/membership/components/start-tenant-form.tsx:44:47 messages/failure-text: The root error of a form shows a failed submit.
src/domain/membership/components/start-tenant-form.tsx:44:73 messages/failure-text: Do not show the message of an error.
src/domain/membership/components/start-tenant-form.tsx:44:89 messages/failure-text: Do not show the message of an error.
src/domain/membership/components/start-tenant-form.tsx:56:64 messages/failure-text: The root error of a form shows a failed submit.
src/examples/workshops/components/workshop-edit-form.tsx:85:24 messages/failure-text: Do not show the message of an error.
src/hooks/use-server-errors.ts:28:42 messages/failure-text: Do not show the message of an error.
src/hooks/use-server-errors.ts:28:58 messages/failure-text: Do not show the message of an error.
src/routes/(examples)/weather.tsx:164:48 messages/failure-text: Do not show the message of an error.
$ pnpm exec tsc -b (errors in these files)
src/domain/membership/components/start-tenant-form.tsx(56,70): error TS2339: Property 'displayMessage' does not exist on type 'ProblemDetailsError'.
src/examples/workshops/components/workshop-edit-form.tsx(85,11): error TS2322: Type '{ noun: string; problem: SaveProblem | null; isLoadingLatest: boolean; loadFailure: string | null; onLoadLatest: () => Promise<void>; }' is not assignable 
src/routes/(examples)/weather.tsx(93,9): error TS2322: Type 'unknown' is not assignable to type 'ReactNode'.

@pdevito3

Copy link
Copy Markdown
Owner Author

review-gate: passed 2879decd

Two rounds of pdstack:thermo-nuclear-review-subagent (opus). Round 1 at e0338332 found two mediums: setError called on its own got past the root-error check, and a message read after a shape check, a cast, destructuring, or a type parameter got past the message check. Both are fixed, with lint tests. Round 2 at 2879decd found no high or medium findings.

Round 2 lows fixed after that review, in 6268971: a field name that starts with "root", the detail and title read by destructuring or a quoted key, Error(...) with no new, and a quoted 'message' key.

Open, low:

  • Home page: "Your user did not load. Reload the page." does not show failureText. A QueryError there would repeat the toast (the A record that does not load shows the same text in the alert and the toast #485 class), so the toast gives the cause.
  • StaleVersionAlert.loadError: unknown uses null for no error, as TanStack's error does. A type that leaves out undefined would need a cast at each caller.
  • A root error that gets failureText through a variable is flagged. The lint error says what to write.

@pdevito3

Copy link
Copy Markdown
Owner Author

PASS+NOTES

Independent verify of PR head 2180ddf merged into base main 3c2817a (merge commit 951c31bb, clean), compared with 3c2817a alone. Both stacks ran isolated with ZeroFactor and the dev build, one at a time.

Real app: each failure kind, base vs land

Recipe failure-texts.mjs makes each kind happen in the real stack and writes the texts on the screen to JSON. invites.mjs covers the 403 and the join refusals. Both recipes passed on each stack, and the console had only Failed to load resource lines.

Kind How Base Land
Form save, 5xx CSharpRepl: InitiateUserAndTenant throws root error "The server could not complete the request. Try again in a moment.", focus on the submit button same
404 refusal /users/<unknown id> "The user did not load." + Server text "User was not found." same
Query, 5xx GetUserList throws QueryError + toast, server-fault text same
Time limit GetUserList waits 90 s (SPA limit 35 s) timed-out text same
Server stopped aspire resource server stop Vite answers 504 after 30 s, so timed-out text; home "The Server could not load your user." timed-out text; home "Your user did not load. Reload the page." (named change)
No answer browser refuses the /api/v1/users connection while online "The app could not reach the server. Check your connection, then try again." same
403 refusal plain member opens Users (invites.mjs) "You cannot see the users of the tenant. Ask a tenant admin for access." same
401 CSharpRepl: JwtBearer SignatureValidator throws (Bearer invalid_token, empty body) toast "The Server did not accept your sign-in..." "The server did not accept your sign-in..." (lowercase, named change)

All 16 ARIA snapshots of invites.mjs match between base and land, apart from ports, times, and tokens. A script diff of the two JSON files finds only the two named changes.

Screenshots (land): ../fullstacktemplate-worktrees/verify-543-evidence/land/failure-texts/01-form-5xx.png to 08-sign-in-401.png, and land/invites/15-users-plain-member.png, 09-join-revoked.png. Base has the same names under verify-543-evidence/base/. Texts: base/texts-base.json, land/texts-land.json.

Developer checks (scratch code, removed)

  • show(new Error('Check your connection, then try again.')), error.problemDetails.detail, error.message on a ProblemDetailsError, and setError('root.server', { message: '...' }) each fail messages/failure-text, and each error names failureText.
  • query.error.message fails tsc -b with TS2339: Property 'message' does not exist on type '{}'. The forms a developer reaches for next (instanceof Error ? query.error.message, (query.error as Error).message, as { message: string }) each fail the lint with the failureText message.

CI bar (land worktree, local)

pnpm lint 0, pnpm build 0, pnpm test 910 passed (96 files), pnpm test:e2e 370 passed.

Notes (none block)

  1. Low: the tsc error on query.error.message does not name failureText. Only the lint error on the next form does.
  2. Low: String(error) and `${error}` get past both the lint and the type check. The PR does not claim these forms.
  3. Low: on a 401, the home page shows three texts with three next steps: the membership banner (Try Again), "Your user did not load. Reload the page.", and the toast (log out and log in again). "Reload the page" does not fix a 401. Base showed the same three messages with its own wording. This is the open low in the review-gate comment.
  4. Base already does this: in dev, a stopped Server reads as "did not answer in time", because the Aspire proxy holds the connection and Vite answers 504 after 30 s.
  5. Not driven in the UI: the stale-version alert loadError, the weather page, the workshop refetch error, the app-fault kind (no user path reaches it), and a 401 with a problem body (DPoP). Unit tests cover them.

@pdevito3
pdevito3 merged commit 2bcdf72 into main Nov 22, 2026
21 of 23 checks passed
@pdevito3
pdevito3 deleted the correct/spa-error-text branch November 22, 2026 11:13
pdevito3 added a commit that referenced this pull request Nov 22, 2026
…rue (#546)

## Why

The `api-contract` and `without-examples` jobs fail on `main` since
#543. Six `messages/failure-text` cases in
`frontend/eslint.config.test.js` get no report in CI, and pass locally.

## What changed

`failureTextMessages` in the test sets
`disallowAutomaticSingleRunInference: true` on its own `ESLint`.

With `CI=true`, typescript-eslint infers a single run. In that mode it
counts the parses of each path, and takes each parse after the first for
a `--fix` pass, so it gives the file an isolated program with no imports
and no default lib. Every test lints the same path,
`src/components/query-error.tsx`, so each test after the first got no
types, and `isError` and `isProblemText` found nothing. The first case,
which needs no types, passed.

## Blast Radius

Test only. `eslint.config.js` is unchanged, and `pnpm lint` in CI parses
each file once, so the rule keeps its types there.

## Verification

- Reproduced the six failures locally with `CI=true pnpm vitest run
eslint.config.test.js`.
- After the change: 92 of 92 pass with `CI=true` and without it, and
`CI=true pnpm test` passes 910 of 910. `pnpm lint` is clean.

Co-authored-by: Amp <amp@ampcode.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant