## TL;DR

SA4006 fires when you assign to `err` and then overwrite it before ever reading the first value  -  usually a swallowed error. Restructure so each error is checked before reassignment, or assign to `_` when the value is intentionally dropped.

## Error

```text
main.go:58:2: this value of err is never used (SA4006)
```

## Steps

1. Look at the flagged line: find where `err` is assigned and where it is next read or overwritten. Expected: you see an assignment like `err = doThing()` followed by another `err = ...` with no check in between.
2. Insert a check before the second assignment: `if err != nil { return err }`. Expected: SA4006 clears because the value is now read.
3. If the first error is intentionally irrelevant, discard it explicitly: `_ = doThing()` or `_, err := ...` restructured. Expected: no unused value remains.
4. Re-run `staticcheck ./...` locally. Expected: exit 0 and the PR gate passes.

## When to use

- staticcheck reports SA4006 on an `err` variable in the PR diff.
- The code reassigns `err` in a sequence of calls.

## When not to use

- The diagnostic is a different SA code (e.g. SA4017, SA4023)  -  each has its own fix.
- The value is genuinely needed later; then the code has a logic bug, not a lint problem.

## Tool compatibility

- staticcheck 2023.1+ (honnef.co/go/tools).
- Go 1.17+.

## Variant phrasings

### SA4006 on a non-err variable

Same pattern: the value is overwritten before use; restructure or remove the dead assignment.

### SA4006 inside a loop

The first iteration's value is dropped; check or reset the variable at the top of the loop body.

## Why it happens

SA4006 detects a value that is assigned but provably never read  -  most often an error from an earlier call that gets silently replaced by a later call's error, hiding the original failure.

## Edge cases

- Shadowing `err` with `:=` inside an if-block can hide the outer value; SA4006 on the outer one means the inner shadow took over.
- Fixing SA4006 by deleting the first call changes behavior; prefer checking the error over removing the call.
- Some codebases intentionally overwrite err in cleanup paths; a short comment plus explicit `_ =` keeps the lint green and the intent clear.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_1R92ssLGUb8gMIypb_Lg4g
