Will It Vibe logoWill It Vibe?
GO-016Low severity-4 points

fmt.Errorf uses %v instead of %w for an error

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

fmt.Errorf formats err with %v, which stringifies it, instead of %w, which wraps it so errors.Is and errors.As can still find it further up the call stack. Once %v is used the original error value is unrecoverable to callers.

Why it matters

fmt.Errorf with %v formats an error into a plain string: the returned error no longer has any structural relationship to the original one, so a caller further up the stack that uses errors.Is or errors.As to check for a specific underlying error (a sentinel like sql.ErrNoRows, or a typed error) will not find it, even though the message printed to a log looks the same. %w instead wraps the original error so it stays discoverable through the whole chain of callers.

How to fix it

Change the %v that formats the error argument to %w. This only changes how the error is wrapped internally; the printed message stays the same, but errors.Is/errors.As can now see through to the original error. Only use %w once per Errorf call, on the actual error being wrapped, not on unrelated string or numeric arguments.

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