Skip to content

Commit 7bbaedd

Browse files
trueadmdummdidumm
andauthored
fix: rethrow errors from await block if no catch block exists (#13819)
* chore: highlight swallowed errors from await blocks in DEV * chore: highlight swallowed errors from await blocks in DEV * chore: highlight swallowed errors from await blocks in DEV * lint * feedback * feedback * add test * Update packages/svelte/tests/runtime-runes/samples/await-no-catch-error/main.svelte --------- Co-authored-by: Simon H <[email protected]>
1 parent 81f9bdd commit 7bbaedd

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

.changeset/blue-boats-call.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: rethrow errors from await block if no catch block exists

packages/svelte/src/internal/client/dom/blocks/await.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ export function await_block(node, get_input, pending_fn, then_fn, catch_fn) {
131131
// but let's use internal_set for consistency and just to be safe
132132
internal_set(error_source, error);
133133
update(CATCH, true);
134+
if (!catch_fn) {
135+
// Rethrow the error if no catch block exists
136+
throw error_source.v;
137+
}
134138
}
135139
);
136140

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { flushSync } from 'svelte';
2+
import { test } from '../../test';
3+
4+
export default test({
5+
async test({ assert, target }) {
6+
const b1 = target.querySelector('button');
7+
8+
let err = '';
9+
window.addEventListener('error', (e) => {
10+
e.preventDefault();
11+
err = e.message;
12+
});
13+
14+
b1?.click();
15+
await Promise.resolve();
16+
flushSync();
17+
18+
assert.throws(() => {
19+
throw err;
20+
}, /Test/);
21+
}
22+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<script>
2+
const promise = Promise.reject('Test');
3+
let toggle = $state(false);
4+
</script>
5+
6+
<button onclick={() => toggle = !toggle}>toggle</button>
7+
8+
{#if toggle}
9+
{#await promise}{/await}
10+
{/if}

0 commit comments

Comments
 (0)