Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Some async code doesn't produce stack trace on error #2704

@dhbaird

Description

@dhbaird

What version of Bun is running?

0.5.9

What platform is your computer?

Linux

What steps can reproduce the bug?

async function aBroken() {
}

async function bBroken() {
    await aBroken();
    throw new Error("Oops"); // <-- no stack trace for this throw
}

async function cBroken() {
    await bBroken();
}

async function aOkay() {
}

async function bOkay() {
    throw new Error("Oops");
    await aOkay();
}

async function cOkay() {
    await bOkay();
}

async function main() {
    try {
        await cBroken();
    }
    catch (e) {
        console.log(e);

        // >>>(bun)
        // 1 | async function aBroken() {
        // 2 | }
        // 3 | 
        // 4 | async function bBroken() {
        // 5 |     await aBroken();
        // 6 |     throw new Error("Oops");
        //               ^
        // error: Oops
        //       at /.../throwy.ts:6:10

        // >>>(node)
        // Error: Oops
        //     at bBroken (/.../throwy.js:6:11)
        //     at async cBroken (/.../throwy.js:10:5)
        //     at async main (/.../throwy.js:27:9)
    }
    try {
        await cOkay();
    }
    catch (e) {
        console.log(e);
        // 
        // >>>(bun)
        // 12 | 
        // 13 | async function aOkay() {
        // 14 | }
        // 15 | 
        // 16 | async function bOkay() {
        // 17 |     throw new Error("Oops");
        //               ^
        // error: Oops
        //       at /.../throwy.ts:17:10
        //       at bOkay (/.../throwy.ts:16:20)
        //       at /.../throwy.ts:22:10
        //       at cOkay (/.../throwy.ts:21:20)
        //       at /.../throwy.ts:50:14

        // >>>(node)
        // Error: Oops
        //     at bOkay (/.../throwy.js:17:11)
        //     at cOkay (/.../throwy.js:22:11)
        //     at main (/.../throwy.js:50:15)
    }
}

main();

What is the expected behavior?

Expect stack trace for the first case.

What do you see instead?

Stack trace is missing.

        // error: Oops
        //       at /.../throwy.ts:6:10

Additional information

Thanks!! :) (Thought that maybe this should be a feature - but the bug reporting template was more useful, so I picked that.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingjscRelated to an issue in JavaScriptCore

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions