Skip to content

Add a unhandledrejection event handler #3159

Open

Description

@kainino0x

The unhandledrejection event fires when a promise rejects without having a rejection handler attached yet. This indicates one of two scenarios:

  • We have some async bubble in between creation of the promise and awaiting it, where it can reject before we await. This is bad because it will (intentionally) crash node, but not awful because it can't cause a false positive.
  • There's a bug where the Promise is not awaited at all before the end of the test; this is a bigger problem as it can cause false positives.

We have a lint rule which ensures we don't drop promises on the floor, but it won't catch when we do something like const p = ... and then misuse it.

We should do something at runtime to at least try to catch these. I don't know what exactly, but maybe have it set a flag that's asserted to be false after the end of a "run". We'd probably want a short "sleep" between the end of the last test and the end of the run to give promises an opportunity to reject. There's no obvious place to put this right now, because different runtimes run things differently, but we should try to do something here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions