Promise Result Ignored
ID |
javascript.promise_result_ignored |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Reliability |
Language |
JavaScript |
Tags |
async, error-handling, reliability |
Description
Reports an expression statement whose entire content is a bare call to an async function — no await, no .then()/.catch()/.finally() chain:
async function fetchData() { ... }
async function main() {
fetchData(); // FLAW — returned Promise is dropped on the floor
}
Rationale
The Promise returned by an async call carries the call’s eventual completion and its rejection. Dropping it has two costs:
-
the caller cannot synchronise with the operation — the next line runs while
fetchDatais still in progress, and the program may exit before it completes, -
any rejection becomes an unhandled rejection. Modern runtimes log a warning, browsers and Node may even crash the process; older code may silently mask the error.
Remediation
Pick the option that matches the intent:
// Wait for the Promise to settle.
await fetchData();
// Fire-and-forget but handle errors explicitly.
fetchData().catch((err) => log(err));
// Forward the Promise to a caller that does handle it.
return fetchData();
Notes
The rule fires only when the call is the entire value of an ExpressionStatement. Calls used in any larger expression — assignments, returns, arguments, .then() chains — are not reported because the result is being consumed.
The "is async" check resolves the called identifier to its declaration. Calls to functions whose async-ness is hidden behind a layer of indirection (e.g. a method that is async only at runtime via a factory) are not detected.