Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for async stack traces #14

Open
ErkoKnoll opened this issue Sep 4, 2019 · 5 comments
Open

Add support for async stack traces #14

ErkoKnoll opened this issue Sep 4, 2019 · 5 comments

Comments

@ErkoKnoll
Copy link

Starting from Node 12 it is possible to enable async stack traces which adds additional 'async' prefix part: https://thecodebarbarian.com/async-stack-traces-in-node-js-12

I think currently the parsing won't work properly if the stack trace contains 'async' prefix.

@Calamari
Copy link
Contributor

Calamari commented Sep 4, 2019

Thanks for pointing to this new feature. I will check it out and see if we have to adapt things there.

@Calamari
Copy link
Contributor

Calamari commented Sep 9, 2019

Finally got to it. No work needed here, but I added some more tests. Do you agree? Or do you see another case where it might go wrong?

@ErkoKnoll
Copy link
Author

ErkoKnoll commented Sep 10, 2019

Your tests are indeed passing and I managed to find out why my case was failing. I was returning stack trace from V8 that had the file name set to script, to fix it I had to changed the file name into /script.js.

Since that workaround works for me you can close the issue, but I also wrote the test case for it if you are interested:

V8: {
    message: 'Oops',
    name: 'Error',
    stack:
      'Error: Oops\n' +
      '    at foo (script:22:11)\n' +
      '    at async bar (script:18:5)\n' +
      '    at async script:5:18'
  },
it('parses V8 async errors', () => {
    const stackFrames = stackTraceParser.parse(
      CapturedExceptions.V8.stack
    );
    expect(stackFrames.length).to.be(3);
    expect(stackFrames[0]).to.eql({
      file: 'script',
      methodName: 'foo',
      arguments: [],
      lineNumber: 22,
      column: 11,
    });
    expect(stackFrames[1]).to.eql({
      file: 'script',
      methodName: 'async bar',
      arguments: [],
      lineNumber: 18,
      column: 5,
    });
    expect(stackFrames[2]).to.eql({
      file: 'script',
      methodName: 'async',
      arguments: [],
      lineNumber: 5,
      column: 18,
    });
  });

@Calamari
Copy link
Contributor

Thanks for the feedback, since this sounds like a valid thing that can happen, I think this should work as well.
Out of curiousity, how did you end up with a filename without a .js ending?

I think it might also be a problem when catching erros in the REPL, (also I think that case is a very, very, very rare edge case g).

@ErkoKnoll
Copy link
Author

ErkoKnoll commented Sep 10, 2019

I'm interacting with V8 directly and I can assign file names separately from the actual content. But indeed, it's a very rare edge case that can be easily fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants