defer Close with no error check
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
defer f.Close() discards whatever error Close returns, so a failed flush or write-back on close is never surfaced. This is a common and often acceptable pattern for read-only files; treat it as a low-priority reminder to check the error deliberately anywhere a write actually happens on close.
Why it matters
defer f.Close() runs Close but throws away whatever error it returns. For most read-only files this is genuinely low risk since a failed Close on a file opened for reading rarely indicates lost data. For a file or connection you have been writing to, though, Close can be the point where a buffered write actually gets flushed to disk or to the network, and an error there means data was not durably saved even though every earlier Write call reported success.
How to fix it
For files or connections you only read from, defer f.Close() as is is a reasonable, low-risk simplification. For anything you write to, check the error explicitly: wrap it in a named return value, or use a small helper like `defer func() { if cerr := f.Close(); cerr != nil { err = cerr } }()` so a close failure on a write path is not silently lost.
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