From 1ea94111cb8b69801994c3359d1ce760ef8be6ce Mon Sep 17 00:00:00 2001 From: Reversean Date: Wed, 24 Dec 2025 12:32:56 +0300 Subject: [PATCH 1/2] feat(sveltekit-integration): add global error handlers test pages in sveltekit playground --- packages/sveltekit/playground/README.md | 28 +++ packages/sveltekit/playground/src/app.css | 169 ++++++++++++++++++ .../sveltekit/playground/src/hooks.client.ts | 8 + .../playground/src/routes/+page.svelte | 60 +++++++ .../errors/promise-rejection/+page.svelte | 15 ++ .../routes/errors/runtime-error/+page.svelte | 15 ++ 6 files changed, 295 insertions(+) create mode 100644 packages/sveltekit/playground/src/routes/errors/promise-rejection/+page.svelte create mode 100644 packages/sveltekit/playground/src/routes/errors/runtime-error/+page.svelte diff --git a/packages/sveltekit/playground/README.md b/packages/sveltekit/playground/README.md index 8151b23..09f6dac 100644 --- a/packages/sveltekit/playground/README.md +++ b/packages/sveltekit/playground/README.md @@ -5,6 +5,9 @@ Test playground for Hawk Error Tracker integration with SvelteKit. ## Table of Contents - [Getting Started](#getting-started) +- [Hawk Integration](#hawk-integration) +- [Error Handling](#error-handling) +- [Error Test Pages](#error-test-pages) ## Getting Started @@ -40,3 +43,28 @@ Hawk automatically registers global error handlers for: - `window.onerror` - `window.onunhandledrejection` + +## Error Handling + +### Global Error Handlers (๐Ÿ”ด) + +Global browser error handlers that catch unhandled errors: + +- **`window.error`** +- **`window.unhandledrejection`** + +**Note:** global errors will be caught using Hawk Catcher. + +## Error Test Pages + +The playground includes test pages to demonstrate each error catching mechanism: + +### Global Error Handlers (๐Ÿ”ด) + +1. **Runtime Error** (`/errors/runtime-error`) + - Demonstrates synchronous error in event handler + - Caught by `window.error` + +2. **Promise Rejection** (`/errors/promise-rejection`) + - Demonstrates unhandled Promise rejection + - Caught by `window.unhandledrejection` diff --git a/packages/sveltekit/playground/src/app.css b/packages/sveltekit/playground/src/app.css index e69de29..40f3c7b 100644 --- a/packages/sveltekit/playground/src/app.css +++ b/packages/sveltekit/playground/src/app.css @@ -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; +} diff --git a/packages/sveltekit/playground/src/hooks.client.ts b/packages/sveltekit/playground/src/hooks.client.ts index 4154746..c5b84ef 100644 --- a/packages/sveltekit/playground/src/hooks.client.ts +++ b/packages/sveltekit/playground/src/hooks.client.ts @@ -5,3 +5,11 @@ if (import.meta.env.VITE_HAWK_TOKEN) { token: import.meta.env.VITE_HAWK_TOKEN, }); } + +window.addEventListener('error', (event) => { + console.error('๐Ÿ”ด [window.error]', event.error, `at ${event.filename}:${event.lineno}`); +}); + +window.addEventListener('unhandledrejection', (event) => { + console.error('๐Ÿ”ด [window.unhandledrejection]', event.reason); +}); diff --git a/packages/sveltekit/playground/src/routes/+page.svelte b/packages/sveltekit/playground/src/routes/+page.svelte index dcea8f7..564ba4f 100644 --- a/packages/sveltekit/playground/src/routes/+page.svelte +++ b/packages/sveltekit/playground/src/routes/+page.svelte @@ -1,3 +1,63 @@ + + Hawk Javascript SvelteKit Integration Playground + +
+
+

๐Ÿงช SvelteKit Error Handling Test Suite

+
+ +
+ โš ๏ธ Testing Instructions: +
    +
  • Open your browser's DevTools Console to see error logs
  • +
  • Look for colored emoji markers: +
      +
    • ๐Ÿ”ด = Caught by global window.error or window.unhandledrejection
    • +
    +
  • +
  • Each test demonstrates where errors are caught in the SvelteKit error handling hierarchy
  • +
+
+ + {#each categories as category} +
+

{category}

+
+ {#each errorTests.filter(t => t.category === category) as test} + +

{test.title}

+

{test.description}

+
+ {/each} +
+
+ {/each} +
diff --git a/packages/sveltekit/playground/src/routes/errors/promise-rejection/+page.svelte b/packages/sveltekit/playground/src/routes/errors/promise-rejection/+page.svelte new file mode 100644 index 0000000..3a9213b --- /dev/null +++ b/packages/sveltekit/playground/src/routes/errors/promise-rejection/+page.svelte @@ -0,0 +1,15 @@ + + +
+

Unhandled Promise Rejection Test

+

Click the button to trigger an unhandled promise rejection.

+

Caught by: window.unhandledrejection (๐Ÿ”ด red dot in console)

+ + +
diff --git a/packages/sveltekit/playground/src/routes/errors/runtime-error/+page.svelte b/packages/sveltekit/playground/src/routes/errors/runtime-error/+page.svelte new file mode 100644 index 0000000..c3dc671 --- /dev/null +++ b/packages/sveltekit/playground/src/routes/errors/runtime-error/+page.svelte @@ -0,0 +1,15 @@ + + +
+

Window Error Handler Test

+

Click the button to trigger a runtime error.

+

Caught by: window.onerror (๐Ÿ”ด red dot in console)

+ + +
From 1812102c389c60afd9a1702cf85a4853d8ddd3d0 Mon Sep 17 00:00:00 2001 From: Reversean Date: Wed, 24 Dec 2025 12:38:24 +0300 Subject: [PATCH 2/2] feat(sveltekit-integration): add error boundary test page in sveltekit playground --- packages/sveltekit/playground/README.md | 24 +++++++++++++ .../playground/src/routes/+page.svelte | 9 +++++ .../errors/component-render/+page.svelte | 36 +++++++++++++++++++ .../component-render/ErrorComponent.svelte | 9 +++++ 4 files changed, 78 insertions(+) create mode 100644 packages/sveltekit/playground/src/routes/errors/component-render/+page.svelte create mode 100644 packages/sveltekit/playground/src/routes/errors/component-render/ErrorComponent.svelte diff --git a/packages/sveltekit/playground/README.md b/packages/sveltekit/playground/README.md index 09f6dac..59f2e34 100644 --- a/packages/sveltekit/playground/README.md +++ b/packages/sveltekit/playground/README.md @@ -55,6 +55,23 @@ Global browser error handlers that catch unhandled errors: **Note:** global errors will be caught using Hawk Catcher. +### Error Boundaries (๐ŸŸก) + +Svelte `` catches errors during: + +- Component rendering (synchronous errors in component body) +- Component initialization + +Example usage: + +```svelte + + + +``` + +**Note:** error boundaries will be caught using Hawk Catcher. + ## Error Test Pages The playground includes test pages to demonstrate each error catching mechanism: @@ -68,3 +85,10 @@ The playground includes test pages to demonstrate each error catching mechanism: 2. **Promise Rejection** (`/errors/promise-rejection`) - Demonstrates unhandled Promise rejection - Caught by `window.unhandledrejection` + +### Error Boundaries (๐ŸŸก) + +3. **Component Render Error** (`/errors/component-render`) + - Demonstrates error during component rendering + - Caught by `` + diff --git a/packages/sveltekit/playground/src/routes/+page.svelte b/packages/sveltekit/playground/src/routes/+page.svelte index 564ba4f..c9b0d9e 100644 --- a/packages/sveltekit/playground/src/routes/+page.svelte +++ b/packages/sveltekit/playground/src/routes/+page.svelte @@ -20,6 +20,14 @@ 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))); @@ -41,6 +49,7 @@
  • Look for colored emoji markers:
    • ๐Ÿ”ด = Caught by global window.error or window.unhandledrejection
    • +
    • ๐ŸŸก = Caught by <svelte:boundary>
  • Each test demonstrates where errors are caught in the SvelteKit error handling hierarchy
  • diff --git a/packages/sveltekit/playground/src/routes/errors/component-render/+page.svelte b/packages/sveltekit/playground/src/routes/errors/component-render/+page.svelte new file mode 100644 index 0000000..215a44d --- /dev/null +++ b/packages/sveltekit/playground/src/routes/errors/component-render/+page.svelte @@ -0,0 +1,36 @@ + + +
    +

    Error Boundary - Rendering Test

    +

    Click the button to trigger a component rendering error.

    +

    Caught by: <svelte:boundary> (๐ŸŸก yellow dot in console)

    + + + + {#snippet fallback(error)} +
    +

    Error Boundary Caught Error

    +

    Message: {error.message}

    +
    + {/snippet} + + + {#if showError} + + {/if} + +
    diff --git a/packages/sveltekit/playground/src/routes/errors/component-render/ErrorComponent.svelte b/packages/sveltekit/playground/src/routes/errors/component-render/ErrorComponent.svelte new file mode 100644 index 0000000..13dc02d --- /dev/null +++ b/packages/sveltekit/playground/src/routes/errors/component-render/ErrorComponent.svelte @@ -0,0 +1,9 @@ + + +
    This should not render if error is thrown