Skip to content

Commit b0071b8

Browse files
committed
Keep SvelteKit client error reporting synchronous
1 parent 2244e33 commit b0071b8

8 files changed

Lines changed: 19 additions & 25 deletions

File tree

‎.agents/skills/exceptionless-javascript/references/client-node.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ await Exceptionless.processQueue();
6969
7070
## SvelteKit 3
7171
72-
Configure the adapter through the `sveltekit` plugin in `vite.config.js`; hook types are exported from `@sveltejs/kit/hooks`. SvelteKit 3 calls error hooks for expected application and framework errors as well as unexpected errors, so inspect `kind` and report `unknown` errors as exceptions when preserving the previous behavior. Use `@exceptionless/browser` in `hooks.client.js` and `@exceptionless/node` in `hooks.server.js`. The complete example is in `example/svelte-kit`.
72+
Configure the adapter through the `sveltekit` plugin in `vite.config.js`; hook types are exported from `@sveltejs/kit/hooks`. SvelteKit 3 calls error hooks for expected application and framework errors as well as unexpected errors, so inspect `kind` and report `unknown` errors as exceptions when preserving the previous behavior. Use `@exceptionless/browser` in `hooks.client.js` and `@exceptionless/node` in `hooks.server.js`. Keep the client hook synchronous when it reports in the background so it also works during rendering. The complete example is in `example/svelte-kit`.
7373
7474
## Source Anchors
7575

‎example/svelte-kit/README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
## Exceptionless Svelte Kit Example
1+
## Exceptionless SvelteKit Example
22

33
This example uses `@exceptionless/browser` in the client and `@exceptionless/node` on the server. SvelteKit 3 passes errors to `hooks.client.js` and `hooks.server.js`; the hooks report unexpected errors and leave expected application, framework, and validation errors to SvelteKit.
44

5-
SvelteKit 3 requires Node.js 22.17 or later. The adapter is configured through `sveltekit({ adapter: adapter() })` in `vite.config.js`, and the hook types come from `@sveltejs/kit/hooks`. See the [SvelteKit 3 migration guide](https://svelte.dev/docs/kit/migrating-to-sveltekit-3) for other requirements.
5+
SvelteKit 3 requires Node.js 22.17 or later. The adapter is configured through `sveltekit({ adapter: adapter() })` in `vite.config.js`, `jsconfig.json` extends `$app/tsconfig`, and the hook types come from `@sveltejs/kit/hooks`. See the [SvelteKit 3 migration guide](https://svelte.dev/docs/kit/migrating-to-sveltekit-3) for other requirements.
66

77
To run locally, follow these steps:
88

99
1. `git clone https://github.com/exceptionless/Exceptionless.JavaScript`
1010
2. `cd Exceptionless.JavaScript`
1111
3. `npm ci`
12-
4. `npm run build`
12+
4. `npm run build --workspace=packages/core --workspace=packages/browser --workspace=packages/node`
1313
5. `npm run dev --workspace=example/svelte-kit -- --open`
1414

1515
The sample is configured for a local test server. Update its API key and server URL in the client and server hooks to send events to your own instance.

‎example/svelte-kit/jsconfig.json‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
"skipLibCheck": true,
1010
"sourceMap": true,
1111
"strict": true
12-
}
13-
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias and https://kit.svelte.dev/docs/configuration#files
14-
//
15-
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
16-
// from the referenced tsconfig.json - TypeScript does not merge them in
12+
},
13+
"include": ["src", "test", "*.js"]
1714
}

‎example/svelte-kit/package.json‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json --watch"
1111
},
1212
"dependencies": {
13-
"@exceptionless/browser": "3.0.0-dev"
13+
"@exceptionless/browser": "3.0.0-dev",
14+
"@exceptionless/node": "3.0.0-dev",
15+
"cookie": "^2.0.2"
1416
},
1517
"devDependencies": {
1618
"@sveltejs/adapter-auto": "^9.0.0",
1719
"@sveltejs/kit": "^3.4.0",
1820
"@sveltejs/vite-plugin-svelte": "^7.3.1",
19-
"cookie": "^2.0.2",
2021
"svelte": "^5.57.1",
2122
"svelte-check": "^4.7.6",
2223
"typescript": "^6.0.3",

‎example/svelte-kit/src/hooks.client.js‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ Exceptionless.startup((c) => {
88
c.defaultTags.push("Example", "svelte-kit", "client");
99
});
1010

11-
/** @type {import('@sveltejs/kit/hooks').HandleClientError} */
12-
export const handleError = async ({ error, event, kind }) => {
13-
if (kind !== "unknown") {
14-
return;
11+
/** @type {import("@sveltejs/kit/hooks").HandleClientError} */
12+
export const handleError = ({ error, kind }) => {
13+
if (kind === "unknown") {
14+
Exceptionless.submitException(toError(error)).catch(console.error);
1515
}
16-
console.warn({ error, event, kind, source: "client error handler" });
17-
await Exceptionless.submitException(toError(error));
1816
};

‎example/svelte-kit/src/hooks.server.js‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ Exceptionless.startup((c) => {
1010

1111
/** @type {import("@sveltejs/kit/hooks").HandleServerError} */
1212
export const handleError = async ({ error, kind }) => {
13-
if (kind !== "unknown") {
14-
return;
13+
if (kind === "unknown") {
14+
await Exceptionless.submitException(toError(error)).catch(console.error);
1515
}
16-
console.log("server error handler");
17-
await Exceptionless.submitException(toError(error));
1816
};

‎example/svelte-kit/vite.config.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import adapter from "@sveltejs/adapter-auto";
22
import { sveltekit } from "@sveltejs/kit/vite";
3-
import { defineConfig } from "vitest/config";
3+
import { defineConfig } from "vite";
44

55
export default defineConfig({
66
plugins: [sveltekit({ adapter: adapter() })]

‎package-lock.json‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)