Skip to content

Async stack trace stitching #442

@andrieshiemstra

Description

@andrieshiemstra

When you call await in async functions, it truncates the stack trace on errors.

For example, this:

async function a() {
    await b();
}

async function b() {
    await 1;
    throw Error("poof");
}

a().catch((ex) => {
    console.error(ex);
});

will result in a stack trace like this:

Error: poof
    at b (test_ex3.js:8:16)

But when we remove the await 1; statement we get the full stack:

Error: poof
    at b (test_ex3.js:8:16)
    at a (test_ex3.js:3:12)
    at <eval> (test_ex3.js:11:2)

Could async stack capture be built into QuickJS? For example, by copying the current stack to JSJobEntry when scheduling and then restoring the stack when executing pending jobs. Perhaps this could be enabled only when a DEBUG_PRESERVE_ASYNC_STACKS flag is set.

For reference:

Spidermonkey only does it when debugger tools are open: https://bugzilla.mozilla.org/show_bug.cgi?id=1601179
V8 has a more elaborate solution http://bit.ly/v8-zero-cost-async-stack-traces

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions