Skip to content

Unable to report unhandled promises  #203

Open
@jazzfog

Description

@jazzfog

Description

This, I guess, is more of a feature request than an issue:
It would be great to be able to report all the un-handled promises. Meaning: for every async-function call require an await before or .then() after.

Use case:

Consider an async function validating a username and returning Promise<boolean>.

const isUsernameValid = async (name: string) => {
    return (await findUserByName(name)).length === 0;
};

Using this function it is easy to forget to use await before the it

// Error: this will always result in "Register user" because the promise
// object is getting implicitly converted to `true`
if (isUsernameValid(name)) {
    // Register user
} else {
    // Show error
}

Expected behavior: Report un-handled promises and require either await before

if (await isUsernameValid(name)) { ... }

or .then() - now the promise is not un-handled, this will indicate that the awaiting is not desired

function createUser() {
    await createDbRecord();

    // Not waiting for the async function to resolve, at the same time 
    // indication that we are aware that we are making an async call.
    logRegistration().then();
}

JetBrains IDEs have this check but it would be great to catch this in CI

prom-1
prom-2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions