Open Bug 1839237 Opened 1 year ago Updated 1 year ago

awaiting for already rejected Promise in console does not throw

Categories

(DevTools :: Console, defect, P3)

Firefox 114
defect

Tracking

(Not tracked)

People

(Reporter: user729569, Unassigned)

References

(Blocks 1 open bug)

Details

Attachments

(3 files)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/114.0

Steps to reproduce:

let prom = new Promise((resolve, reject) => { reject(new Error("hello")) })
// we get "Uncaught (in promise) Error: hello"
await prom // we get nothing

Actual results:

See code comments above.

Expected results:

Error thrown every time we await.

Both Chrome and Node do this.

Attached image chrome-latest.png

Chrome behavior

Attached image node-latest.png

Node behavior

Attached image firefox-latest.png

Firefox behavior

Status: UNCONFIRMED → NEW
Component: Untriaged → Console
Ever confirmed: true
Product: Firefox → DevTools
Summary: Rejected Promise Throws Error Only Once → awaiting for already rejected Promise in console does not throw

Hello, I don't know how to @ here on this ancient platform, but this bug isn't just limited to the DevTools, it is also present on web pages executing JavaScript.

(In reply to [:user729569] from comment #4)

Hello, I don't know how to @ here on this ancient platform, but this bug isn't just limited to the DevTools, it is also present on web pages executing JavaScript.

Oh, I did some light testing and wasn't able to reproduce outside of DevTools.
Can you write a script demonstrating the issue (not running in DevTools) ?

Flags: needinfo?(rizwaanb10)
<html>

<head>
    <script>
        (async () =>
        {
            let prom = new Promise((resolve, reject) => { reject(new Error("hello")) })
            // we get "Uncaught (in promise) Error: hello"
            await prom // we get nothing
            await prom // we get nothing

            try
            {
                await prom // we get nothing
            }
            catch (e) // never happens. proof that error is not re-thrown.
            {
                console.log("Error awaiting rejected promise - Good")
                console.log(e)
            }
        })()
    </script>
</head>

<body>
    hello
</body>

</html>
Flags: needinfo?(rizwaanb10)

! Ignore the code snippet above !

<html>

<head>
    <script>
        (async () =>
        {
            let prom = new Promise((resolve, reject) => { reject(new Error("hello")) })
            // we get "Uncaught (in promise) Error: hello"

            try
            {
                await prom // we get nothing
            }
            catch (e) // never happens. proof that error is not re-thrown.
            {
                console.log("Error awaiting rejected promise - Good")
                console.log(e)
            }
        })()
    </script>
</head>

<body>
    hello
</body>

</html>

Actually, with this ☝️, the catch block does execute, so I think you're right, it is just a DevTools bug 🙂

This could be improved by having a dedicated mode for the console (tracked at Bug 1839588).
Not a recent regression, P3 S3, but would be nice to fix even before we get the dedicated mode. Contributions would be appreciated.

Blocks: 1839588
Severity: -- → S3
Priority: -- → P3

probably caused by https://searchfox.org/mozilla-central/rev/c0adc2160976e2c118e2e5709d08aac071fddce9/devtools/server/actors/webconsole.js#900-902

// The promise was rejected. We let the engine handle this as it will report a
// `uncaught exception` error.
response.topLevelAwaitRejected = true;
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: