endo icon indicating copy to clipboard operation
endo copied to clipboard

bare Error instance does not log correctly

Open kumavis opened this issue 3 years ago • 9 comments

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

kumavis avatar Nov 30 '21 22:11 kumavis

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)]

kumavis avatar Nov 30 '21 23:11 kumavis

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
  }
}

kumavis avatar Nov 30 '21 23:11 kumavis

first '%ErrorPrototype%': { constructor: true } breaks the logging of errors adding '%ObjectPrototype%': { 'constructor': true } fixes the logging of errors

kumavis avatar Nov 30 '21 23:11 kumavis

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

kumavis avatar Dec 01 '21 00:12 kumavis

this api may allow us to customize and fix output https://github.com/nodejs/node/blob/7633c86eebbf6e381e60e63dc6e3eb36a3cce276/lib/internal/util/inspect.js#L294-L304

kumavis avatar Dec 01 '21 02:12 kumavis

neat hack, if you add a constructor property on the Error instance, it will log correctly in node

Object.defineProperty(err, 'constructor', { value: Error })

kumavis avatar Dec 01 '21 03:12 kumavis

See #636

erights avatar Dec 01 '21 03:12 erights

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

Anastasia1510 avatar Aug 07 '22 06:08 Anastasia1510

Do you have a reason to turn on consoleTaming: 'unsafe'? Without it, do you see error stacks?

erights avatar Aug 07 '22 17:08 erights