Go: assignment mismatch: 1 variable but os.Open returns 2 values
The number of variables on the left does not match the number of values the function returns.
assignment mismatch: 1 variable but returns 2 valuesassignment mismatch: 2 variables but f returns 1 valueassignment mismatch: 1 variable but os.Open returns 2 valuesf() (no value) used as valuemultiple-value in single-value context Meaning
Go functions often return (value, error). Capture both (f, err := os.Open(p)) or discard with _. The same error appears when a function returns nothing but you assign its result.
Common causes
- Ignoring the error return
- Function changed to return an extra value
- Using the result of a function that returns nothing
- Wrong number in
returnstatement - Range over map with one variable of wrong kind
⚡ Quick fix
f, err := os.Open(p); if err != nil { … }- Use
_for values you don't need - Update callers after signature changes
Detailed fix by platform
Go
- Never ignore errors silently; run
go vetanderrcheckto find them
How to diagnose
- Returns — How many values?
- Left — Variables count?
- Error — Handled?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- cannot assign to struct field m[k].f in map Go: cannot assign to struct field users["bob"].Age in map
- cannot refer to unexported name Go: cannot refer to unexported name pkg.helper (undefined: pkg.helper)
- cannot use x as type in assignment/argument Go: cannot use "5" (untyped string constant) as int value in argument to f
Most viewed in Go
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 4 Nov 2026