Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/repl/src/lib/Output/Viewer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@
error = null;
}
} catch (e) {
console.error(e); // make it show up in the console, too, not just the UI
// @ts-ignore
show_error(e);
}
Expand Down
21 changes: 19 additions & 2 deletions packages/repl/src/lib/Repl.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
onversion?: (version: string) => void;
onchange?: () => void;
download?: () => void;
/**
* Invoked whenever there's a bundler or runtime error
*/
onerror?: (error: Error) => void;
}

let {
Expand All @@ -40,7 +44,8 @@
previewTheme = 'light',
onversion,
onchange = () => {},
download
download,
onerror
}: Props = $props();

// TODO pass in real data
Expand Down Expand Up @@ -185,6 +190,18 @@
$toggleable = mobile && orientation === 'columns' && embedded !== 'output-only';
});

$effect(() => {
if (runtime_error) {
onerror?.(runtime_error);
}
});

$effect(() => {
if (bundler.result?.error) {
onerror?.(bundler.result.error as Error);
}
});

let runes = $derived(
workspace.current.name.endsWith('.svelte.js') ||
(workspace.current_compiled?.result?.metadata.runes ?? false)
Expand Down Expand Up @@ -235,7 +252,7 @@
{injectedCSS}
{previewTheme}
{workspace}
runtimeError={runtime_error}
bind:runtimeError={runtime_error}
/>
</section>
{/snippet}
Expand Down
1 change: 1 addition & 0 deletions packages/repl/src/lib/public.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { OutputChunk, RollupError } from '@rollup/browser';
import type { CompileError } from 'svelte/compiler';

export interface BundleResult {
uid: number;
Expand Down
9 changes: 8 additions & 1 deletion packages/repl/src/routes/v0.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@
</script>

<main>
<Repl bind:this={repl} embedded="output-only" />
<Repl
bind:this={repl}
embedded="output-only"
onerror={(error) => {
// @ts-expect-error so that v0 can react to REPL errors
window.__svelte_repl_onerror?.(error);
}}
/>
</main>

<style>
Expand Down
Loading