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 <5968653+dummdidumm@users.noreply.github.com>
revert-13651-compile-warning
Dominic Gannaway 2 weeks ago committed by GitHub
parent 81f9bdd376
commit 7bbaedd6c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: rethrow errors from await block if no catch block exists

@ -131,6 +131,10 @@ export function await_block(node, get_input, pending_fn, then_fn, catch_fn) {
// but let's use internal_set for consistency and just to be safe
internal_set(error_source, error);
update(CATCH, true);
if (!catch_fn) {
// Rethrow the error if no catch block exists
throw error_source.v;
}
}
);

@ -0,0 +1,22 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
async test({ assert, target }) {
const b1 = target.querySelector('button');
let err = '';
window.addEventListener('error', (e) => {
e.preventDefault();
err = e.message;
});
b1?.click();
await Promise.resolve();
flushSync();
assert.throws(() => {
throw err;
}, /Test/);
}
});

@ -0,0 +1,10 @@
<script>
const promise = Promise.reject('Test');
let toggle = $state(false);
</script>
<button onclick={() => toggle = !toggle}>toggle</button>
{#if toggle}
{#await promise}{/await}
{/if}
Loading…
Cancel
Save