fix: don't define `error.message` if it's not configurable (#16149)

* fix: don't define `error.message` if it's not configurable

* fix: print console.error with updated stack

* fix: revert second `console.error`
pull/16157/head
Paolo Ricciuti 3 months ago committed by GitHub
parent da63318191
commit 113a3daab2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: don't define `error.message` if it's not configurable

@ -3,7 +3,7 @@ import { DEV } from 'esm-env';
import { FILENAME } from '../../constants.js';
import { is_firefox } from './dom/operations.js';
import { BOUNDARY_EFFECT, EFFECT_RAN } from './constants.js';
import { define_property } from '../shared/utils.js';
import { define_property, get_descriptor } from '../shared/utils.js';
import { active_effect } from './runtime.js';
/**
@ -63,6 +63,12 @@ function adjust_error(error, effect) {
if (adjusted_errors.has(error)) return;
adjusted_errors.add(error);
const message_descriptor = get_descriptor(error, 'message');
// if the message was already changed and it's not configurable we can't change it
// or it will throw a different error swallowing the original error
if (message_descriptor && !message_descriptor.configurable) return;
var indent = is_firefox ? ' ' : '\t';
var component_stack = `\n${indent}in ${effect.fn?.name || '<unknown>'}`;
var context = effect.ctx;

@ -0,0 +1,8 @@
import { test } from '../../test';
export default test({
compileOptions: {
dev: true
},
error: 'test'
});

@ -0,0 +1,11 @@
<script>
class CustomError extends Error {
constructor() {
super();
Object.defineProperty(this, "message", {
value: "test"
});
}
}
throw new CustomError()
</script>
Loading…
Cancel
Save