Skip to content

Commit 0adc671

Browse files
trueadmRich-Harris
andauthored
Update packages/svelte/src/internal/client/runtime.js
Co-authored-by: Rich Harris <[email protected]>
1 parent a53f258 commit 0adc671

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

packages/svelte/src/internal/client/runtime.js

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,18 @@ function handle_error(error, effect, component_context) {
255255

256256
const component_stack = [];
257257

258+
const effect_name = effect.fn.name;
259+
260+
if (effect_name) {
261+
// If we have an effect name, it means it happened in the template, $effect or $effect.pre.
262+
Object.defineProperty(error, '__skip_hydration_retry', {
263+
value: true,
264+
enumerable: false
265+
});
266+
267+
component_stack.push(effect_name);
268+
}
269+
258270
/** @type {import("#client").ComponentContext | null} */
259271
let current_context = component_context;
260272

@@ -268,27 +280,9 @@ function handle_error(error, effect, component_context) {
268280

269281
current_context = current_context.p;
270282
}
271-
const effect_name = effect.fn.name;
272-
273-
if (effect_name) {
274-
// If we have an effect name, it means it happened in the template, $effect or $effect.pre.
275-
Object.defineProperty(error, '__skip_hydration_retry', {
276-
value: true,
277-
enumerable: false
278-
});
279-
}
280-
281-
let component_stack_string =
282-
`Svelte caught an error thrown by ${component_stack[0]}${effect_name ? ` during a${effect_name.startsWith('$') ? 'n' : ''} ${effect_name}` : ''}.` +
283-
` You should fix this error in your code.\n\nError: ${error.message}\n\nThe component stack when this error occured:\n`;
284-
285-
for (const name of component_stack) {
286-
component_stack_string += `\t${name}\n`;
287-
}
288-
289-
component_stack_string += '\nThe error is located at:\n';
290283

291-
error.message = component_stack_string;
284+
const indent = /Firefox/.test(navigator.userAgent) ? ' ' : '\t';
285+
error.message += `\n${component_stack.map((name) => `\n${indent}in ${name}`).join('')}\n`;
292286

293287
const stack = error.stack;
294288

0 commit comments

Comments
 (0)