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

async stack traces #2703

Closed
nayeemrmn opened this issue Jul 31, 2019 · 6 comments · Fixed by #4690
Closed

async stack traces #2703

nayeemrmn opened this issue Jul 31, 2019 · 6 comments · Fixed by #4690

Comments

@nayeemrmn
Copy link
Collaborator

nayeemrmn commented Jul 31, 2019

(async () => {
  await Promise.resolve().then(() => {
    const error = new Error;
    console.log(error.stack);
    throw error;
  });
})();
Error: 
    at file:///mnt/c/Users/Nayeem/projects/deno/temp.js:3:19
    at async file:///mnt/c/Users/Nayeem/projects/deno/temp.js:2:3
error: Uncaught Error
    at file:///mnt/c/Users/Nayeem/projects/deno/temp.js:3:19

This is very important. It prevents error stack traces for asynchronous ops from reaching the faulting user code.

ry added a commit to ry/deno that referenced this issue Aug 1, 2019
@nayeemrmn nayeemrmn changed the title Deno's error stack trace stops at Promise callbacks, giving less information than the native 'error.stack' Deno's error stack trace doesn't show async stack frames. Aug 1, 2019
@nayeemrmn nayeemrmn changed the title Deno's error stack trace doesn't show async stack frames. Deno's error stack trace doesn't show async stack frames Aug 1, 2019
@ry ry changed the title Deno's error stack trace doesn't show async stack frames async stack traces Aug 2, 2019
@ry
Copy link
Member

ry commented Aug 2, 2019

@nayeemrmn
Copy link
Collaborator Author

nayeemrmn commented Aug 2, 2019

The was also the constructor issue:

class DenoError extends Error {
  constructor() {
    super();
  }
}

const error = new DenoError;
console.log(error.stack);
throw error;
Error: 
    at file:///mnt/c/Users/Nayeem/projects/deno/temp2.js:7:15
error: Uncaught Error
    at DenoError (file:///mnt/c/Users/Nayeem/projects/deno/temp2.js:3:5)
    at file:///mnt/c/Users/Nayeem/projects/deno/temp2.js:7:15

Ref https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#Custom_Error_Types

There seem to just be general discrepancies between error.stack and the automatically printed one, as if the latter is being populated using outdated logic. Might be a quick fix in that case but the whole thing is very weird.

@ry
Copy link
Member

ry commented Aug 2, 2019

@Nayeem-Rahman let's handle that one separately in #2710 ... I suspect there are two different problems, and #2710 is easier.

@nayeemrmn
Copy link
Collaborator Author

nayeemrmn commented Aug 3, 2019

Okay, two stack traces are captured by ErrorUtils::Construct() whenever an error is constructed:

The first is captured by Isolate::CaptureAndSetDetailedStackTrace() and is stored in the exception under the symbol factory()->detailed_stack_trace_symbol().

The second is captured by Isolate::CaptureAndSetSimpleStackTrace() and is stored in the exception under the symbol factory()->stack_trace_symbol().

@bartlomieju
Copy link
Member

Done in #2820?

@nayeemrmn
Copy link
Collaborator Author

Done in #2820?

@bartlomieju No, that just ensures DenoErrors aren't constructed in the message handler so their call stack includes user code.

This is about the stack trace printed by Deno when aborting on an uncaught error. The one we currently get from V8 isn't the same one that error.stack uses, it doesn't include async frames and another problem described in #2710. Turns out V8 captures two different stacks traces with two different sets of rules.

@ry These should be one issue: Use the same stack trace as error.stack when aborting. Node and Chrome definitely do.

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

Successfully merging a pull request may close this issue.

3 participants