Skip to content
Latchkey

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.

go
./classify.go:14:1: missing return at end of function

Common 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

  1. Return a sensible value or error at the end of the function.
  2. Or add a default branch that returns or panics.
Go
default:
	return fmt.Errorf("unhandled case: %v", x)

Panic on truly unreachable paths

  1. If the end really cannot be reached, make that explicit with a panic.
Go
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.

Frequently asked questions

What causes ""missing return""?
An if/else or switch handles known cases but leaves the function end reachable without a return.
How do I fix "missing return"?
Add a terminating return

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card