Skip to content
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

svelte:boundary doesn't catch errors inside a @const tag #15368

Open
therealsujitk opened this issue Feb 22, 2025 · 1 comment · May be fixed by #15369
Open

svelte:boundary doesn't catch errors inside a @const tag #15368

therealsujitk opened this issue Feb 22, 2025 · 1 comment · May be fixed by #15369

Comments

@therealsujitk
Copy link

Describe the bug

When an error is thrown inside the {@const} tag, <svelte:boundary> doesn't catch it.

This snippet works as expected:

<script>
  function fail() {
    throw new Error('💣');
  }
</script>

<h1>Hello!</h1>

<svelte:boundary>
  <span>{fail()}</span>

  {#snippet failed()}
    <p>Somethning went wrong :(</p>
  {/snippet}
</svelte:boundary>

However, this doesn't:

<script>
  function fail() {
    throw new Error('💣');
  }
</script>

<h1>Hello!</h1>

<svelte:boundary>
  {@const result = fail()}
  <span>{result}</span>

  {#snippet failed()}
    <p>Somethning went wrong :(</p>
  {/snippet}
</svelte:boundary>

Reproduction

https://svelte.dev/playground/5bcbda8a665d489fa8d36977a7ebb551?version=5.20.2

Logs

System Info

System:
    OS: macOS 15.3.1
    CPU: (10) arm64 Apple M2 Pro
    Memory: 264.11 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.15.1 - /opt/homebrew/bin/node
    npm: 10.7.0 - /opt/homebrew/bin/npm
    pnpm: 8.15.4 - /opt/homebrew/bin/pnpm
    bun: 1.1.18 - /opt/homebrew/bin/bun
  Browsers:
    Brave Browser: 131.1.73.91
    Safari: 18.3
  npmPackages:
    svelte: ^5.20.2 => 5.20.2

Severity

annoyance

@adiguba
Copy link
Contributor

adiguba commented Feb 22, 2025

Hello,

Note that the code is only present on dev mode, as it add an extra $.get(result)

Generated code :

		const result = $.derived_safe_equal(fail);

+		$.get(result);

Source :

// we need to eagerly evaluate the expression in order to hit any
// 'Cannot access x before initialization' errors
if (dev) {
context.state.init.push(b.stmt(b.call('$.get', declaration.id)));
}

I think I can fix that...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants