Skip to content

Commit

Permalink
fix: assign message to error object in handle_error using Object.assi…
Browse files Browse the repository at this point in the history
…gn (#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 <rich.harris@vercel.com>

* Update .changeset/shiny-pillows-relax.md

Co-authored-by: Rich Harris <rich.harris@vercel.com>

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

Co-authored-by: Rich Harris <rich.harris@vercel.com>

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

Co-authored-by: Rich Harris <rich.harris@vercel.com>

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

---------

Co-authored-by: Rich Harris <rich.harris@vercel.com>
  • Loading branch information
trueadm and Rich-Harris authored Jun 2, 2024
1 parent e560044 commit 14ddb87
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/shiny-pillows-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte": patch
---

fix: assign message to error object in `handle_error` using `Object.defineProperty`
8 changes: 6 additions & 2 deletions packages/svelte/src/internal/client/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,9 @@ function handle_error(error, effect, component_context) {
}

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

const stack = error.stack;

Expand All @@ -326,7 +328,9 @@ function handle_error(error, effect, component_context) {
}
new_lines.push(line);
}
error.stack = new_lines.join('\n');
define_property(error, 'stack', {
value: error.stack + new_lines.join('\n')
});
}

handled_errors.add(error);
Expand Down

0 comments on commit 14ddb87

Please sign in to comment.