File tree Expand file tree Collapse file tree
packages/sveltekit/playground Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -57,6 +57,30 @@ Global browser error handlers that catch unhandled errors:
5757
5858** Caught by Hawk Catcher.**
5959
60+ ### Error Boundaries (🟢)
61+
62+ Svelte ` <svelte:boundary> ` catches errors during:
63+
64+ - Component rendering (synchronous errors in component body)
65+ - Component initialization
66+
67+ Example usage:
68+
69+ ``` sveltehtml
70+ <svelte:boundary onerror={handleBoundaryError} {failed}>
71+ <ErrorProneComponent />
72+ </svelte:boundary>
73+
74+ {#snippet failed(error, reset)}
75+ <div class="error-fallback">
76+ <p>Error: {error.message}</p>
77+ <button onclick={reset}>Reset</button>
78+ </div>
79+ {/snippet}
80+ ```
81+
82+ ** Not caught by Hawk Catcher.**
83+
6084## Error Test Pages
6185
6286The playground includes test pages to demonstrate each error catching mechanism:
@@ -70,3 +94,10 @@ The playground includes test pages to demonstrate each error catching mechanism:
70942 . ** Promise Rejection** (` /errors/promise-rejection ` )
7195 - Demonstrates unhandled Promise rejection
7296 - Caught by window event listener ` unhandledrejection `
97+
98+ ### Error Boundaries (🟢) - Not caught by Hawk
99+
100+ 1 . ** Boundary Error** (` /errors/boundary ` )
101+ - Demonstrates svelte boundary feature
102+ - Caught by ` <svelte:boundary> `
103+
Original file line number Diff line number Diff line change 2020 href: ' /errors/promise-rejection' ,
2121 category: ' Global Error Handlers (🟡)'
2222 },
23+
24+ // Error Boundaries
25+ {
26+ title: ' Boundary Error' ,
27+ description: ' Error caught by svelte:boundary' ,
28+ href: ' /errors/boundary' ,
29+ category: ' Error Boundaries (🟢)'
30+ },
2331 ];
2432
2533 const categories = Array .from (new Set (errorTests .map (t => t .category )));
4149 <li >Look for colored emoji markers:
4250 <ul >
4351 <li >🟡 = Caught by global <code >window.error</code > or <code >window.unhandledrejection</code ></li >
52+ <li >🟢 = Caught by <code ><svelte:boundary></code ></li >
4453 </ul >
4554 </li >
4655 <li >Each test demonstrates where errors are caught in the SvelteKit error handling hierarchy</li >
Original file line number Diff line number Diff line change 1+ <script lang =" ts" >
2+ import ErrorComponent from ' ./ErrorComponent.svelte' ;
3+
4+ let showError = $state (false );
5+
6+ function triggerError() {
7+ showError = ! showError ;
8+ }
9+
10+ function handleBoundaryError(error : Error ) {
11+ console .error (' 🟢 [svelte:boundary] Caught error:' , error );
12+ }
13+ </script >
14+
15+ <div class =" container" >
16+ <h1 >Error Boundary Test</h1 >
17+ <p >Click the button to trigger a rendering error.</p >
18+ <p ><strong >Caught by:</strong > <code ><svelte:boundary></code > (🟢 green dot in console)</p >
19+
20+ <button onclick ={triggerError } disabled ={showError }>
21+ Trigger Error
22+ </button >
23+
24+ {#snippet failed (error , reset )}
25+ <div class =" error-fallback" >
26+ <h3 >Error Boundary Caught Error</h3 >
27+ <p >Message: {error .message }</p >
28+ <button onclick ={() => { showError = false ; reset (); }}>Reset</button >
29+ </div >
30+ {/ snippet }
31+
32+ <svelte:boundary onerror ={handleBoundaryError } {failed }>
33+ {#if showError }
34+ <ErrorComponent />
35+ {/if }
36+ </svelte:boundary >
37+ </div >
Original file line number Diff line number Diff line change 1+ <script lang =" ts" >
2+ throw new Error (' Error caught by svelte:boundary' );
3+ </script >
4+
5+ <div >This should not render if error is thrown</div >
You can’t perform that action at this time.
0 commit comments