Skip to content

Commit 14ddb87

Browse files
trueadmRich-Harris
andauthored
fix: assign message to error object in handle_error using Object.assign (#11675)
* fix: avoid writing to not writable error object in handle_error * feedback * feedback * Update packages/svelte/src/internal/client/runtime.js Co-authored-by: Rich Harris <[email protected]> * Update .changeset/shiny-pillows-relax.md Co-authored-by: Rich Harris <[email protected]> * Update packages/svelte/src/internal/client/runtime.js Co-authored-by: Rich Harris <[email protected]> * Update packages/svelte/src/internal/client/runtime.js Co-authored-by: Rich Harris <[email protected]> * Update packages/svelte/src/internal/client/runtime.js --------- Co-authored-by: Rich Harris <[email protected]>
1 parent e560044 commit 14ddb87

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

.changeset/shiny-pillows-relax.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte": patch
3+
---
4+
5+
fix: assign message to error object in `handle_error` using `Object.defineProperty`

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,9 @@ function handle_error(error, effect, component_context) {
311311
}
312312

313313
const indent = /Firefox/.test(navigator.userAgent) ? ' ' : '\t';
314-
error.message += `\n${component_stack.map((name) => `\n${indent}in ${name}`).join('')}\n`;
314+
define_property(error, 'message', {
315+
value: error.message + `\n${component_stack.map((name) => `\n${indent}in ${name}`).join('')}\n`
316+
});
315317

316318
const stack = error.stack;
317319

@@ -326,7 +328,9 @@ function handle_error(error, effect, component_context) {
326328
}
327329
new_lines.push(line);
328330
}
329-
error.stack = new_lines.join('\n');
331+
define_property(error, 'stack', {
332+
value: error.stack + new_lines.join('\n')
333+
});
330334
}
331335

332336
handled_errors.add(error);

0 commit comments

Comments
 (0)