Unhandled Promise
fetch and database calls with no await, return or assignment
warningReliability
unhandled-promiseWhy this matters
A promise nobody awaits runs in the background with no error handling. If it fails, nothing tells you. prodlint tracks fetch() and Prisma-style database calls that start a statement on their own.
Example
app/api/signup/route.tsexport async function POST(req: Request) {
const data = await req.json();
// Fire-and-forget: if this fails, nobody finds out
fetch("https://api.example.com/events", {
method: "POST",
body: JSON.stringify({ type: "signup", email: data.email }),
});
return Response.json({ ok: true });
}app/api/signup/route.tsexport async function POST(req: Request) {
const data = await req.json();
await fetch("https://api.example.com/events", {
method: "POST",
body: JSON.stringify({ type: "signup", email: data.email }),
});
return Response.json({ ok: true });
}How to fix
Await the call, or add .catch() if you really mean fire-and-forget. Use Promise.allSettled() for parallel work where some calls may fail.
Reference
- In the output
- Findings carry
"ruleId": "unhandled-promise"in--jsonand the same id in SARIF and in the terminal. - Silence one line
// prodlint-disable-next-line unhandled-promise- Silence a whole file
// prodlint-disable unhandled-promiseat the top of the file- How it works
- Matches text patterns. Source on GitHub