-
Notifications
You must be signed in to change notification settings - Fork 3
fix(frontend): add error boundaries so one render throw doesn't blank the app #159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
121ce37
fix(frontend): add error boundaries so one render throw doesn't blank…
11a197e
fix(review): address Greptile findings on #159
lucastononro 9a1681e
merge: PR #157 — type the SSE event layer with a discriminated union …
lucastononro 6ec0868
chore(staging): ledger row — PR #157
lucastononro a71d33e
fix(review): key FileViewer's markdown ErrorBoundary by filePath (Gre…
lucastononro e21700b
style: prettier --write page.tsx (branch predates CI format gate)
lucastononro f55645b
merge: staging-v0.0.5 into fix/102-error-boundary (repair #159)
lucastononro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| 'use client'; | ||
|
|
||
| import { useEffect } from 'react'; | ||
| import { AlertCircle, RefreshCw } from 'lucide-react'; | ||
|
|
||
| // Route-level error boundary (Next.js App Router convention: a file named | ||
| // `error.tsx` automatically wraps its route segment — here, the whole app, | ||
| // since this lives directly under `src/app/`). Catches render errors thrown | ||
| // anywhere in the tree below it that aren't already contained by a nested | ||
| // boundary (see `src/components/ErrorBoundary.tsx`, used around the | ||
| // workspace canvas and chat markdown renderers) and shows a recoverable | ||
| // screen instead of Next's default error overlay / a blank page. | ||
| export default function Error({ | ||
| error, | ||
| reset, | ||
| }: { | ||
| error: Error & { digest?: string }; | ||
| reset: () => void; | ||
| }) { | ||
| useEffect(() => { | ||
| console.error('Route-level error boundary caught:', error); | ||
| }, [error]); | ||
|
|
||
| return ( | ||
| <div className="flex min-h-screen flex-col items-center justify-center gap-4 bg-black p-8 text-center"> | ||
| <AlertCircle className="w-10 h-10 text-red-400" /> | ||
| <div> | ||
| <h1 className="text-lg font-medium text-gray-100">Something went wrong</h1> | ||
| <p className="mt-2 max-w-md text-sm text-gray-400"> | ||
| Trainable hit an unexpected error. You can try again, or reload the page if it keeps | ||
| happening. | ||
| </p> | ||
| {error.message && ( | ||
| <p className="mt-3 max-w-lg break-words rounded-md border border-white/[0.08] bg-white/[0.04] px-3 py-2 font-mono text-xs text-gray-500"> | ||
| {error.message} | ||
| </p> | ||
| )} | ||
| </div> | ||
| <div className="flex items-center gap-2"> | ||
| <button | ||
| type="button" | ||
| onClick={() => reset()} | ||
| className="inline-flex items-center gap-1.5 rounded-lg bg-primary-600 px-4 py-2 text-sm text-white transition-colors hover:bg-primary-500" | ||
| > | ||
| <RefreshCw className="w-3.5 h-3.5" /> Try again | ||
| </button> | ||
| <button | ||
| type="button" | ||
| onClick={() => window.location.reload()} | ||
| className="inline-flex items-center gap-1.5 rounded-lg border border-white/[0.08] bg-white/[0.06] px-4 py-2 text-sm text-gray-300 transition-colors hover:bg-white/[0.1]" | ||
| > | ||
| Reload page | ||
| </button> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| 'use client'; | ||
|
|
||
| import { useEffect } from 'react'; | ||
|
|
||
| // Root-layout error boundary (Next.js App Router convention). `error.tsx` | ||
| // only catches errors thrown *below* the root layout — if `layout.tsx` | ||
| // itself (or anything providers it mounts, e.g. AppProvider/ToastProvider) | ||
| // throws during render, only `global-error.tsx` can catch it, and to do so | ||
| // it must render its own <html>/<body> since it replaces the root layout | ||
| // entirely while active. It intentionally does NOT depend on | ||
| // globals.css/Tailwind or any app component — those are exactly what may | ||
| // have failed to mount — so everything here is inline-styled and | ||
| // dependency-free. | ||
| export default function GlobalError({ | ||
| error, | ||
| reset, | ||
| }: { | ||
| error: Error & { digest?: string }; | ||
| reset: () => void; | ||
| }) { | ||
| useEffect(() => { | ||
| console.error('Global error boundary caught:', error); | ||
| }, [error]); | ||
|
|
||
| return ( | ||
| <html lang="en"> | ||
| <body | ||
| style={{ | ||
| margin: 0, | ||
| minHeight: '100vh', | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| alignItems: 'center', | ||
| justifyContent: 'center', | ||
| gap: '16px', | ||
| padding: '32px', | ||
| textAlign: 'center', | ||
| backgroundColor: '#000', | ||
| color: '#e5e5e5', | ||
| fontFamily: | ||
| '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif', | ||
| }} | ||
| > | ||
| <div> | ||
| <h1 style={{ fontSize: '18px', fontWeight: 500, margin: 0 }}>Trainable failed to load</h1> | ||
| <p style={{ marginTop: '8px', maxWidth: '420px', fontSize: '14px', color: '#a3a3a3' }}> | ||
| Something went wrong before the app could start. Try again, or reload the page if it | ||
| keeps happening. | ||
| </p> | ||
| {error.message && ( | ||
| <p | ||
| style={{ | ||
| marginTop: '12px', | ||
| maxWidth: '480px', | ||
| wordBreak: 'break-word', | ||
| borderRadius: '6px', | ||
| border: '1px solid rgba(255,255,255,0.08)', | ||
| backgroundColor: 'rgba(255,255,255,0.04)', | ||
| padding: '8px 12px', | ||
| fontFamily: 'ui-monospace, monospace', | ||
| fontSize: '12px', | ||
| color: '#737373', | ||
| }} | ||
| > | ||
| {error.message} | ||
| </p> | ||
| )} | ||
| </div> | ||
| <div style={{ display: 'flex', gap: '8px' }}> | ||
| <button | ||
| type="button" | ||
| onClick={() => reset()} | ||
| style={{ | ||
| borderRadius: '8px', | ||
| border: 'none', | ||
| backgroundColor: '#4f46e5', | ||
| color: '#fff', | ||
| padding: '8px 16px', | ||
| fontSize: '14px', | ||
| cursor: 'pointer', | ||
| }} | ||
| > | ||
| Try again | ||
| </button> | ||
| <button | ||
| type="button" | ||
| onClick={() => window.location.reload()} | ||
| style={{ | ||
| borderRadius: '8px', | ||
| border: '1px solid rgba(255,255,255,0.08)', | ||
| backgroundColor: 'rgba(255,255,255,0.06)', | ||
| color: '#d4d4d4', | ||
| padding: '8px 16px', | ||
| fontSize: '14px', | ||
| cursor: 'pointer', | ||
| }} | ||
| > | ||
| Reload page | ||
| </button> | ||
| </div> | ||
| </body> | ||
| </html> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.