endo
endo copied to clipboard
bare Error instance does not log correctly
ses: (master
at time of writing ac1cc0)
node: v14.17.6 (and v16.9.1, v17.2.0)
require('ses/lockdown');
lockdown({ errorTaming: 'unsafe', stackFiltering: 'verbose', consoleTaming: 'unsafe', domainTaming: 'unsafe' })
console.error(new Error('boom'));
logs only
{}
error stack and message are intact
previous issue https://github.com/endojs/endo/issues/636
with overideTaming: 'min'
[Error: boom
at file:///home/xyz/Development/endo/packages/ses/abc.js:10:13
at ModuleJob.run (internal/modules/esm/module_job.js:170:25)
at async Loader.import (internal/modules/esm/loader.js:178:24)
at async Object.loadESM (internal/process/esm_loader.js:68:5)]
with overideTaming: 'moderate'
(default)
{}
with overideTaming: 'severe'
[Error <Object <[Object: null prototype] {}>>: boom
at file:///home/xyz/Development/endo/packages/ses/abc.js:10:13
at ModuleJob.run (internal/modules/esm/module_job.js:170:25)
at async Loader.import (internal/modules/esm/loader.js:178:24)
at async Object.loadESM (internal/process/esm_loader.js:68:5)]
lockdown({ overrideTaming, errorTaming: 'unsafe', stackFiltering: 'verbose', consoleTaming: 'unsafe' });
console.log(Object.getOwnPropertyDescriptors(Error.prototype));
- min:
{
constructor: {
value: [Function: Error],
writable: false,
enumerable: false,
configurable: false
},
name: {
get: [Function: getter],
set: [Function: setter],
enumerable: false,
configurable: false
},
message: {
value: '',
writable: false,
enumerable: false,
configurable: false
},
toString: {
value: [Function: toString],
writable: false,
enumerable: false,
configurable: false
}
}
- moderate (default):
{
constructor: { get: {}, set: {}, enumerable: false, configurable: false },
name: { get: {}, set: {}, enumerable: false, configurable: false },
message: { get: {}, set: {}, enumerable: false, configurable: false },
toString: { get: {}, set: {}, enumerable: false, configurable: false }
}
- severe:
Object <[Object: null prototype] {}> {
constructor: Object <[Object: null prototype] {}> {
get: [Function: getter] Function <Function <Complex prototype>>,
set: [Function: setter] Function <Function <Complex prototype>>,
enumerable: false,
configurable: false
},
name: Object <[Object: null prototype] {}> {
get: [Function: getter] Function <Function <Complex prototype>>,
set: [Function: setter] Function <Function <Complex prototype>>,
enumerable: false,
configurable: false
},
message: Object <[Object: null prototype] {}> {
get: [Function: getter] Function <Function <Complex prototype>>,
set: [Function: setter] Function <Function <Complex prototype>>,
enumerable: false,
configurable: false
},
toString: Object <[Object: null prototype] {}> {
get: [Function: getter] Function <Function <Complex prototype>>,
set: [Function: setter] Function <Function <Complex prototype>>,
enumerable: false,
configurable: false
}
}
first '%ErrorPrototype%': { constructor: true }
breaks the logging of errors
adding '%ObjectPrototype%': { 'constructor': true }
fixes the logging of errors
trace https://github.com/nodejs/node/blob/7633c86eebbf6e381e60e63dc6e3eb36a3cce276/lib/internal/util/inspect.js#L286 https://github.com/nodejs/node/blob/7633c86eebbf6e381e60e63dc6e3eb36a3cce276/lib/internal/util/inspect.js#L726 https://github.com/nodejs/node/blob/7633c86eebbf6e381e60e63dc6e3eb36a3cce276/lib/internal/util/inspect.js#L796
https://github.com/nodejs/node/blob/7633c86eebbf6e381e60e63dc6e3eb36a3cce276/lib/internal/util/inspect.js#L554
why constructor
as getter is problematic ^
for:
-
(no relevant enablements)
constructor is 'Error'
https://github.com/nodejs/node/blob/7633c86eebbf6e381e60e63dc6e3eb36a3cce276/lib/internal/util/inspect.js#L803
for:
-
'%ErrorPrototype%': { constructor: true }
constructor is 'Object'
https://github.com/nodejs/node/blob/7633c86eebbf6e381e60e63dc6e3eb36a3cce276/lib/internal/util/inspect.js#L803
for:
-
'%ErrorPrototype%': { constructor: true }
-
'%ObjectPrototype%': { 'constructor': true }
constructor is 'Error <Object <[Object: null prototype] {}>>'
https://github.com/nodejs/node/blob/7633c86eebbf6e381e60e63dc6e3eb36a3cce276/lib/internal/util/inspect.js#L803
this api may allow us to customize and fix output https://github.com/nodejs/node/blob/7633c86eebbf6e381e60e63dc6e3eb36a3cce276/lib/internal/util/inspect.js#L294-L304
neat hack, if you add a constructor
property on the Error
instance, it will log correctly in node
Object.defineProperty(err, 'constructor', { value: Error })
See #636
ses: (
master
at time of writing ac1cc0) node: v14.17.6 (and v16.9.1, v17.2.0)require('ses/lockdown'); lockdown({ errorTaming: 'unsafe', stackFiltering: 'verbose', consoleTaming: 'unsafe', domainTaming: 'unsafe' }) console.error(new Error('boom'));
logs only
{}
error stack and message are intact
previous issue #636
Do you have a reason to turn on consoleTaming: 'unsafe'
? Without it, do you see error stacks?