Will It Vibe logoWill It Vibe?
FASTAPI-013Low severity-4 points

BackgroundTasks task with no error handling

Part of Code Quality & Syntax, which counts for 20% of the overall score. When this check fires it deducts 4 points from that category, once per scan, no matter how many places it turns up.

What it detects

A function scheduled with background_tasks.add_task() runs after the response has already been sent, so an unhandled exception inside it is never surfaced to the caller. With no try/except in the task body, a failure such as a bad network call or a missing record is silently swallowed by the server process instead of being logged or retried. Heuristic: only checks the task function when its definition is visible in the same file.

Why it matters

A function passed to background_tasks.add_task() runs after the HTTP response has already been sent, so there is no request left to return an error to. Without a try/except inside the task, any exception it raises (a failed network call, a missing database record, a bad argument) is simply logged by the ASGI server's default handler at best, or silently dropped, and whatever the task was supposed to do (send an email, write an audit record, call a webhook) never happens with no record of why.

How to fix it

Wrap the body of the background task function in a try/except that logs the failure with enough context to debug it (the arguments it was called with, the exception), and consider a retry or a dead-letter record for tasks where silently failing once is unacceptable (payment confirmations, compliance-relevant writes).

The paid report includes a ready-to-paste prompt for your AI coding agent for every check it finds, pointed at the exact findings from your scan. See pricing

Does your repo trip this check?

Paste a GitHub URL or drop a project folder. Scans run in your browser and take seconds.

Scan your repo

Related Code Quality & Syntax checks