Skip to content

refactor: add error boundaries, improve error handling - #73

Open
robsimmons wants to merge 7 commits into
mainfrom
push-xmuqwrsvvrur
Open

refactor: add error boundaries, improve error handling#73
robsimmons wants to merge 7 commits into
mainfrom
push-xmuqwrsvvrur

Conversation

@robsimmons

@robsimmons robsimmons commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

This PR adds normal Next.js error boundaries for handling exceptional, "talk to your administrator" control flows to the application, simplifies some of the logic around encountering those cases (they'll just throw to the error boundary), and handles many cases where exceptions were being ignored.

Distinguishing normal errors and unexpected exceptions

When I was exploring adding new linting rules I observed a (pervasive, common, classic, first line in Next.js docs on error handling) conflation between two different types of server-side errors:

  • Expected in-the-course-of-doing-business errors; ultimately you can't do client-side validation as the final check for "does a project with this name exist," so you need the server function to surface and return these errors. ActionResponse is the right shape for this kind of thing.
  • Genuinely unexpected "something is misconfigured" errors. ("Uncaught exceptions," the next.js docs call them, but I don't like that, possibly because I still have trauma from using Java in the naughts.)

Using ActionResponse for the latter use case, and the combination of SWR and serverAction access patterns, meant that there were places where e.g. an Error was getting as-cast to string and then getting placed in the React document like a string, resulting in an error.

Surfacing errors

This PR addresses quite a number of places where uncaught exceptions are thrown in handlers, and these get ignored completely, or at most with a comment in the console. useThrowingSWR and useThrowToBoundary are introduced as patterns for taking a computation outside of the render phase and catching an error for the purpose of re-throwing it to an error boundary.

Additional

  • Documents conventions in AGENTS for the agents and the humans like me who read AGENTS.
  • Renames the Error component to ErrorBox so it doesn't conflate with built-in Error.
  • Fixes a kind-of-security issue with untrusted error searchParams being authoritatively communicated to users

@robsimmons
robsimmons marked this pull request as draft August 6, 2026 22:00
Comment thread src/app/admin/actions.ts
@robsimmons
robsimmons marked this pull request as ready for review August 6, 2026 23:39
@robsimmons
robsimmons requested a review from Vtec234 August 6, 2026 23:39
apply pattern in a few more cases


more agent commentary
@robsimmons
robsimmons force-pushed the push-xmuqwrsvvrur branch 4 times, most recently from 0bbbbe0 to 2a24b90 Compare August 7, 2026 19:13
@robsimmons robsimmons changed the title refactor: add and use error boundaries refactor: add error boundaries, improve error handling Aug 7, 2026
@robsimmons
robsimmons force-pushed the push-xmuqwrsvvrur branch 2 times, most recently from e01d06a to fb225ae Compare August 7, 2026 21:14
Comment thread src/app/page.tsx

@Vtec234 Vtec234 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, this seems like an improvement.

Comment thread src/app/[userName]/actions.ts Outdated
Comment thread src/app/[userName]/actions.ts Outdated
Comment thread src/lib/client/util.ts
Comment thread src/lib/client/util.ts
Comment thread src/app/admin/actions.ts
Comment thread src/app/setup/page.tsx
Comment thread src/app/global-error.tsx
Comment thread src/app/error.tsx
robsimmons and others added 3 commits August 8, 2026 20:35
Co-authored-by: Wojciech Nawrocki <13901751+Vtec234@users.noreply.github.com>
Co-authored-by: Wojciech Nawrocki <13901751+Vtec234@users.noreply.github.com>
Co-authored-by: Wojciech Nawrocki <13901751+Vtec234@users.noreply.github.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.

2 participants