tapjs / stack-utils

Captures and cleans stack traces.
https://www.npmjs.com/package/stack-utils
MIT License
190 stars 35 forks source link

Does not filter out node internals without function names #48

Closed SimenB closed 4 years ago

SimenB commented 4 years ago
const StackUtils = require('stack-utils');
const stack = new StackUtils({cwd: process.cwd(), internals: StackUtils.nodeInternals()});

stack.clean(`
    at ChannelWrap.emitInitNative (internal/async_hooks.js:136:43)
    at new Resolver (internal/dns/utils.js:23:20)
    at internal/dns/utils.js:101:23
    at NativeModule.compile (internal/bootstrap/loaders.js:285:5)
    at nativeModuleRequire (internal/bootstrap/loaders.js:192:14)
    at dns.js:38:5
    at NativeModule.compile (internal/bootstrap/loaders.js:285:5)
    at NativeModule.compileForPublicLoader (internal/bootstrap/loaders.js:220:8)
    at loadNativeModule (internal/modules/cjs/helpers.js:23:9)
    at Function.Module._load (internal/modules/cjs/loader.js:694:15)
`);

Expected result:

''

Received result:

internal/dns/utils.js:101:23
dns.js:38:5
SimenB commented 4 years ago

My quite hacky workaround:

StackUtils.nodeInternals().reduce(
  (internals, internal) => {
    const sourceWithoutParens = internal.source
      // remove leading and trailing parens (which are escaped) and the $
      .slice(2, internal.source.length - 3);

    return internals.concat(internal, new RegExp(`at ${sourceWithoutParens}$`));
  },
  [],
)
coreyfarrell commented 4 years ago

@SimenB I think #49 should fix this.

One comment, with stack-utils 2.x you do not need to provide internals: StackUtils.nodeInternals() - this is the new default.

SimenB commented 4 years ago

Thanks for the quick PR! We cannot use stack-utils v2 as it explodes in the browser ☹️

coreyfarrell commented 4 years ago

Thanks for the quick PR! We cannot use stack-utils v2 as it explodes in the browser :frowning_face:

Can you give details?

SimenB commented 4 years ago

Actually turned out to be trivial, I just didn't look into it when things exploded previously: https://github.com/facebook/jest/pull/9533

SimenB commented 4 years ago

One comment, with stack-utils 2.x you do not need to provide internals: StackUtils.nodeInternals() - this is the new default.

Should probably update the readme, that's where I got it from. 🙂 In jest we just use StackUtils.nodeInternals() directly, and not the clean function (we also use parse, but I don't think that cares about the internals opt?)