-
Notifications
You must be signed in to change notification settings - Fork 4
3 - Svelte playground - add more error triggers #143
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
Open
Reversean
wants to merge
3
commits into
feature/svelte-playground-hawk-catcher
Choose a base branch
from
feature/svelte-playground-error-triggers
base: feature/svelte-playground-hawk-catcher
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
78061f3
feat(sveltekit-integration): add global error handlers test pages in …
Reversean 74b16fd
feat(sveltekit-integration): add error boundary test page in svelteki…
Reversean 182516f
feat(sveltekit-integration): add SSR error boundary test page in svel…
Reversean 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
Some comments aren't visible on the classic Files Changed page.
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,169 @@ | ||
| @import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap'); | ||
|
|
||
| :root { | ||
| --bg-primary: #2f3341; | ||
| --bg-secondary: #242732; | ||
| --text-primary: #dbe6ff; | ||
| --text-secondary: rgba(219, 230, 255, 0.6); | ||
| --border-color: rgba(219, 230, 255, 0.1); | ||
| --button-primary: #4979e4; | ||
| --button-primary-hover: #4869d2; | ||
| } | ||
|
|
||
| body { | ||
| font-family: Roboto, system-ui, sans-serif; | ||
| margin: 0; | ||
| padding: 0; | ||
| background: var(--bg-primary); | ||
| color: var(--text-primary); | ||
| font-size: 13px; | ||
| } | ||
|
|
||
| header { | ||
| padding: 30px; | ||
| background: var(--bg-secondary); | ||
| } | ||
|
|
||
| h1 { | ||
| font-weight: bold; | ||
| font-size: 20px; | ||
| margin: 0 0 15px; | ||
| color: var(--text-primary); | ||
| } | ||
|
|
||
| h2 { | ||
| font-weight: 500; | ||
| margin: 0 0 10px; | ||
| font-size: 13px; | ||
| color: var(--text-secondary); | ||
| letter-spacing: 0.24px; | ||
| text-transform: uppercase; | ||
| } | ||
|
|
||
| h3 { | ||
| margin: 0 0 10px 0; | ||
| color: var(--text-primary); | ||
| font-size: 16px; | ||
| font-weight: 500; | ||
| } | ||
|
|
||
| p { | ||
| margin: 0.5rem 0; | ||
| color: var(--text-primary); | ||
| } | ||
|
|
||
| a { | ||
| color: inherit; | ||
| text-decoration: underline; | ||
| } | ||
|
|
||
| a:hover { | ||
| color: var(--button-primary); | ||
| } | ||
|
|
||
| section { | ||
| padding: 15px; | ||
| border: 1px solid var(--border-color); | ||
| border-radius: 4px; | ||
| margin: 15px; | ||
| } | ||
|
|
||
| button { | ||
| display: inline-block; | ||
| padding: 8px 20px; | ||
| border: 0; | ||
| border-radius: 5px; | ||
| background: var(--button-primary); | ||
| color: var(--text-primary); | ||
| font-weight: 500; | ||
| font-size: 14px; | ||
| cursor: pointer; | ||
| font-family: inherit; | ||
| } | ||
|
|
||
| button:hover { | ||
| background: var(--button-primary-hover); | ||
| } | ||
|
|
||
| button:disabled { | ||
| opacity: 0.5; | ||
| cursor: not-allowed; | ||
| } | ||
|
|
||
| code { | ||
| background: var(--bg-secondary); | ||
| padding: 2px 6px; | ||
| border-radius: 3px; | ||
| font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace; | ||
| font-size: 0.9em; | ||
| } | ||
|
|
||
| .container { | ||
| max-width: 1200px; | ||
| margin: 0 auto; | ||
| padding: 20px; | ||
| } | ||
|
|
||
| .grid { | ||
| display: grid; | ||
| grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); | ||
| gap: 15px; | ||
| } | ||
|
|
||
| .test-card { | ||
| display: block; | ||
| padding: 20px; | ||
| border: 2px solid var(--border-color); | ||
| border-radius: 8px; | ||
| text-decoration: none; | ||
| color: inherit; | ||
| transition: all 0.2s ease; | ||
| background: var(--bg-secondary); | ||
| } | ||
|
|
||
| .test-card:hover { | ||
| border-color: var(--button-primary); | ||
| transform: translateY(-2px); | ||
| box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3); | ||
| } | ||
|
|
||
| .test-card h3 { | ||
| margin: 0 0 10px 0; | ||
| font-size: 16px; | ||
| } | ||
|
|
||
| .test-card p { | ||
| margin: 0; | ||
| color: var(--text-secondary); | ||
| font-size: 13px; | ||
| line-height: 1.5; | ||
| } | ||
|
|
||
| .alert { | ||
| padding: 15px; | ||
| border-left: 4px solid; | ||
| border-radius: 4px; | ||
| margin: 15px 0; | ||
| } | ||
|
|
||
| .alert-warning { | ||
| background: rgba(255, 193, 7, 0.15); | ||
| border-color: #ffc107; | ||
| color: #ffd54f; | ||
| } | ||
|
|
||
| .error-fallback { | ||
| padding: 1.5rem; | ||
| background: rgba(244, 67, 54, 0.15); | ||
| border-left: 4px solid #f44336; | ||
| border-radius: 4px; | ||
| } | ||
|
|
||
| .error-fallback h3 { | ||
| margin: 0 0 0.5rem 0; | ||
| color: #ff8a80; | ||
| } | ||
|
|
||
| .error-fallback p { | ||
| margin: 0.5rem 0; | ||
| } |
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,10 @@ | ||
| import type { HandleServerError } from '@sveltejs/kit'; | ||
|
|
||
| export const handleError: HandleServerError = async ({ error, event, status, message }) => { | ||
| console.error('🔴 [server.handleError]', error, `at ${event.url.pathname}`); | ||
|
|
||
| return { | ||
| message, | ||
| status, | ||
| }; | ||
| }; |
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 |
|---|---|---|
| @@ -1,3 +1,81 @@ | ||
| <script lang="ts"> | ||
| interface ErrorTest { | ||
| title: string; | ||
| description: string; | ||
| href: string; | ||
| category: string; | ||
| } | ||
|
|
||
| const errorTests: ErrorTest[] = [ | ||
| // Window Error Handlers | ||
| { | ||
| title: 'Synchronous Runtime Error', | ||
| description: 'Error thrown in event handler', | ||
| href: '/errors/runtime-error', | ||
| category: 'Global Error Handlers (🟡)' | ||
| }, | ||
| { | ||
| title: 'Unhandled Promise Rejection', | ||
| description: 'Promise rejected without catch handler', | ||
| href: '/errors/promise-rejection', | ||
| category: 'Global Error Handlers (🟡)' | ||
| }, | ||
|
|
||
| // Error Boundaries | ||
| { | ||
| title: 'Boundary Error', | ||
| description: 'Error caught by svelte:boundary', | ||
| href: '/errors/boundary', | ||
| category: 'Error Boundaries (🟢)' | ||
| }, | ||
|
|
||
| // SSR Errors | ||
| { | ||
| title: 'Server-side Error', | ||
| description: 'Error thrown in load function', | ||
| href: '/errors/server-error', | ||
| category: 'SSR Errors (🔴)' | ||
| }, | ||
| ]; | ||
|
|
||
| const categories = Array.from(new Set(errorTests.map(t => t.category))); | ||
| </script> | ||
|
|
||
| <svelte:head> | ||
| <title>Hawk Javascript SvelteKit Integration Playground</title> | ||
| </svelte:head> | ||
|
|
||
| <div class="container"> | ||
| <header> | ||
| <h1>🧪 SvelteKit Error Handling Test Suite</h1> | ||
| </header> | ||
|
|
||
| <div class="alert alert-warning"> | ||
| <strong>⚠️ Testing Instructions:</strong> | ||
| <ul> | ||
| <li>Open your browser's DevTools Console to see error logs</li> | ||
| <li>Look for colored emoji markers: | ||
| <ul> | ||
| <li>🔴 = SSR error (caught by <code>handleError</code> in hooks.server.ts)</li> | ||
| <li>🟡 = Caught by global <code>window.error</code> or <code>window.unhandledrejection</code></li> | ||
| <li>🟢 = Caught by <code><svelte:boundary></code></li> | ||
| </ul> | ||
| </li> | ||
| <li>Each test demonstrates where errors are caught in the SvelteKit error handling hierarchy</li> | ||
| </ul> | ||
| </div> | ||
|
|
||
| {#each categories as category} | ||
| <section> | ||
| <h2>{category}</h2> | ||
| <div class="grid"> | ||
| {#each errorTests.filter(t => t.category === category) as test} | ||
| <a href={test.href} class="test-card" data-sveltekit-preload-data="off"> | ||
| <h3>{test.title}</h3> | ||
| <p>{test.description}</p> | ||
| </a> | ||
| {/each} | ||
| </div> | ||
| </section> | ||
| {/each} | ||
| </div> |
37 changes: 37 additions & 0 deletions
37
packages/sveltekit/playground/src/routes/errors/boundary/+page.svelte
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,37 @@ | ||
| <script lang="ts"> | ||
| import ErrorComponent from './ErrorComponent.svelte'; | ||
|
|
||
| let showError = $state(false); | ||
|
|
||
| function triggerError() { | ||
| showError = true; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider open/close behaviour with |
||
| } | ||
|
|
||
| function handleBoundaryError(error: Error) { | ||
| console.error('🟢 [svelte:boundary] Caught error:', error); | ||
| } | ||
| </script> | ||
|
|
||
| <div class="container"> | ||
| <h1>Error Boundary Test</h1> | ||
| <p>Click the button to trigger a rendering error.</p> | ||
| <p><strong>Caught by:</strong> <code><svelte:boundary></code> (🟢 green dot in console)</p> | ||
|
|
||
| <button onclick={triggerError} disabled={showError}> | ||
| Trigger Error | ||
| </button> | ||
|
|
||
| {#snippet failed(error, reset)} | ||
| <div class="error-fallback"> | ||
| <h3>Error Boundary Caught Error</h3> | ||
| <p>Message: {error.message}</p> | ||
| <button onclick={() => { showError = false; reset(); }}>Reset</button> | ||
| </div> | ||
| {/snippet} | ||
|
|
||
| <svelte:boundary onerror={handleBoundaryError} {failed}> | ||
| {#if showError} | ||
| <ErrorComponent shouldError={true} /> | ||
| {/if} | ||
| </svelte:boundary> | ||
| </div> | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just so we don't forget to change this