-
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
base: feature/svelte-playground-hawk-catcher
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,72 @@ | ||
| <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: 'Component Rendering Error', | ||
| description: 'Error thrown during component render', | ||
| href: '/errors/component-render', | ||
| category: 'Error Boundaries (🟡)' | ||
| }, | ||
| ]; | ||
|
|
||
| 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>🔴 = 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> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| <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 rendering error:', error); | ||
| } | ||
| </script> | ||
|
|
||
| <div class="container"> | ||
| <h1>Error Boundary - Rendering Test</h1> | ||
| <p>Click the button to trigger a component rendering error.</p> | ||
| <p><strong>Caught by:</strong> <code><svelte:boundary></code> (🟡 yellow dot in console)</p> | ||
|
|
||
| <button onclick={triggerError} disabled={showError}> | ||
| Trigger Rendering Error | ||
| </button> | ||
|
|
||
| {#snippet fallback(error)} | ||
| <div class="error-fallback"> | ||
| <h3>Error Boundary Caught Error</h3> | ||
| <p>Message: {error.message}</p> | ||
| </div> | ||
| {/snippet} | ||
|
|
||
| <svelte:boundary onerror={handleBoundaryError} failed={fallback}> | ||
|
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. Rendering error report request is not being sent to Hawk Tracker because it intercepted by both 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. The approach here will be to implement |
||
| {#if showError} | ||
| <ErrorComponent shouldError={true} /> | ||
| {/if} | ||
| </svelte:boundary> | ||
| </div> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <script lang="ts"> | ||
| let { shouldError }: { shouldError: boolean } = $props(); | ||
|
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. No need in $props() & if statement, just do throw |
||
| if (shouldError) { | ||
| throw new Error('Rendering error caught by svelte:boundary'); | ||
| } | ||
| </script> | ||
|
|
||
| <div>This should not render if error is thrown</div> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <script lang="ts"> | ||
| function triggerRejection() { | ||
| Promise.reject(new Error('Unhandled promise rejection')); | ||
| } | ||
| </script> | ||
|
|
||
| <div class="container"> | ||
| <h1>Unhandled Promise Rejection Test</h1> | ||
| <p>Click the button to trigger an unhandled promise rejection.</p> | ||
| <p><strong>Caught by:</strong> <code>window.unhandledrejection</code> (🔴 red dot in console)</p> | ||
|
|
||
| <button onclick={triggerRejection}> | ||
| Trigger Promise Rejection | ||
| </button> | ||
| </div> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <script lang="ts"> | ||
| function triggerError() { | ||
| throw new Error('Runtime error caught by window.onerror'); | ||
| } | ||
| </script> | ||
|
|
||
| <div class="container"> | ||
| <h1>Window Error Handler Test</h1> | ||
| <p>Click the button to trigger a runtime error.</p> | ||
| <p><strong>Caught by:</strong> <code>window.onerror</code> (🔴 red dot in console)</p> | ||
|
|
||
| <button onclick={triggerError}> | ||
| Trigger Runtime Error | ||
| </button> | ||
| </div> |
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