Skip to content

Conversation

@bnoordhuis
Copy link
Contributor

Fixes: #1248


Definitely work in progress. Currently no way to limit the stack trace size, sometimes records the same stack frame twice, loses track around new Promise(...), and no doubt there's more.

@andrieshiemstra
Copy link
Contributor

It indeed loses the stack when actually awaiting Promises
e.g.

  • await 1; -> stack is preserved
  • await Promise.resolve(1); -> stack is preserved
  • await sleep(1); -> stack is NOT preserved
// emulate a long running function like 'connectToDb'
async function sleep(ms) {
    return await new Promise((res) => {
        setTimeout(res, ms);
    });
}

Also, I see you store the JSAsyncStack in the JSRuntime object, how does that work i you have multiple async stacks.. e.g.

async function sleep(ms) {
    return await new Promise((res) => {
        setTimeout(res, ms);
    });
}

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

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

async function c() {
    await sleep(10);
}

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

Won't that add 'c()' to the error stack of calling a?

My first notion was that we should store the stack in JSJobEntry but I'm not sure how it works with Promises created with js_new_promise_capability should the resolver functions of js_new_promise_capability also store their own stack from where they were created?

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 this pull request may close these issues.

Async stack trace stitching

2 participants