Go "missing return at end of function" - Fix in CI
A function declaring a return value must end every reachable path with a return (or a terminating statement). Go rejects a function whose end is reachable without one.
What this error means
A build fails with missing return at end of function. It typically appears when a switch or if/else covers the expected cases but Go cannot prove the end is unreachable.
./classify.go:14:1: missing return at end of functionCommon causes
A code path falls through without returning
An if/else or switch handles known cases but leaves the function end reachable without a return.
No default in an exhaustive-looking switch
Go does not treat a switch without default as exhaustive, so the function can reach its end.
How to fix it
Add a terminating return
- Return a sensible value or error at the end of the function.
- Or add a default branch that returns or panics.
default:
return fmt.Errorf("unhandled case: %v", x)Panic on truly unreachable paths
- If the end really cannot be reached, make that explicit with a panic.
panic("unreachable")How to prevent it
- Always cover the function end with a return or terminating statement.
- Add default branches to switches that produce a value.
- Build locally to catch missing returns before CI.