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
5 changes: 5 additions & 0 deletions .changeset/swift-taxes-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: less confusing names for inspect errors
11 changes: 10 additions & 1 deletion packages/svelte/src/internal/client/dev/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,17 @@ export function inspect(get_value, inspector, show_stack = false) {
inspector(...snap);

if (!initial) {
const stack = get_stack('$inspect(...)');
// eslint-disable-next-line no-console
console.log(get_stack('UpdatedAt'));

if (stack) {
// eslint-disable-next-line no-console
console.groupCollapsed('stack trace');
// eslint-disable-next-line no-console
console.log(stack);
// eslint-disable-next-line no-console
console.groupEnd();
}
}
} else {
inspector(initial ? 'init' : 'update', ...snap);
Expand Down
3 changes: 1 addition & 2 deletions packages/svelte/src/internal/client/dev/tracing.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ export function get_stack(label) {
});

define_property(error, 'name', {
// 'Error' suffix is required for stack traces to be rendered properly
value: `${label}Error`
value: label
});

return /** @type {Error & { stack: string }} */ (error);
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/src/internal/client/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function proxy(value) {
var is_proxied_array = is_array(value);
var version = source(0);

var stack = DEV && tracing_mode_flag ? get_stack('CreatedAt') : null;
var stack = DEV && tracing_mode_flag ? get_stack('created at') : null;
var parent_version = update_version;

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/src/internal/client/reactivity/deriveds.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function derived(fn) {
};

if (DEV && tracing_mode_flag) {
signal.created = get_stack('CreatedAt');
signal.created = get_stack('created at');
}

return signal;
Expand Down
4 changes: 2 additions & 2 deletions packages/svelte/src/internal/client/reactivity/sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export function source(v, stack) {
};

if (DEV && tracing_mode_flag) {
signal.created = stack ?? get_stack('CreatedAt');
signal.created = stack ?? get_stack('created at');
signal.updated = null;
signal.set_during_effect = false;
signal.trace = null;
Expand Down Expand Up @@ -186,7 +186,7 @@ export function internal_set(source, value) {

if (DEV) {
if (tracing_mode_flag || active_effect !== null) {
const error = get_stack('UpdatedAt');
const error = get_stack('updated at');

if (error !== null) {
source.updated ??= new Map();
Expand Down
4 changes: 2 additions & 2 deletions packages/svelte/src/internal/client/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ export function get(signal) {
if (!tracking && !untracking && !was_read) {
w.await_reactivity_loss(/** @type {string} */ (signal.label));

var trace = get_stack('TracedAt');
var trace = get_stack('traced at');
// eslint-disable-next-line no-console
if (trace) console.warn(trace);
}
Expand All @@ -628,7 +628,7 @@ export function get(signal) {
if (signal.trace) {
signal.trace();
} else {
trace = get_stack('TracedAt');
trace = get_stack('traced at');

if (trace) {
var entry = tracing_expressions.entries.get(signal);
Expand Down
18 changes: 14 additions & 4 deletions packages/svelte/tests/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,15 @@ export const async_mode = process.env.SVELTE_NO_ASYNC !== 'true';
* @param {any[]} logs
*/
export function normalise_inspect_logs(logs) {
return logs.map((log) => {
/** @type {string[]} */
const normalised = [];

for (const log of logs) {
if (log === 'stack trace') {
// ignore `console.group('stack trace')` in default `$inspect(...)` output
continue;
}

if (log instanceof Error) {
const last_line = log.stack
?.trim()
Expand All @@ -210,11 +218,13 @@ export function normalise_inspect_logs(logs) {

const match = last_line && /(at .+) /.exec(last_line);

return match && match[1];
if (match) normalised.push(match[1]);
} else {
normalised.push(log);
}
}

return log;
});
return normalised;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default test({
'Detected reactivity loss when reading `values[1]`. This happens when state is read in an async function after an earlier `await`'
);

assert.equal(warnings[1].name, 'TracedAtError');
assert.equal(warnings[1].name, 'traced at');

assert.equal(warnings.length, 2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default test({
'Detected reactivity loss when reading `b`. This happens when state is read in an async function after an earlier `await`'
);

assert.equal(warnings[1].name, 'TracedAtError');
assert.equal(warnings[1].name, 'traced at');

assert.equal(warnings.length, 2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default test({
try {
flushSync(() => button.click());
} catch (e) {
assert.equal(errors.length, 1); // for whatever reason we can't get the name which should be UpdatedAtError
assert.equal(errors.length, 1); // for whatever reason we can't get the name which should be 'updated at'
assert.ok(/** @type {Error} */ (e).message.startsWith('effect_update_depth_exceeded'));
}
}
Expand Down
Loading