go
syntax
ai_generated
true
multiple-value f() (value of type (T, error)) used in single-value context
ID: go/multiple-value-in-single-context
99%Fix Rate
99%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 121 | active | — | — | — |
| 1 | active | — | — | — |
Root Cause
Calling a function that returns multiple values (typically value, error) in a context that expects a single value.
genericWorkarounds
-
99% success Assign both return values: val, err := fn()
Handle the error: val, err := fn(); if err != nil { return err } -
85% success Use _ to explicitly discard: val, _ := fn()
Only when you're certain the error cannot occur or is irrelevant
Dead Ends
Common approaches that don't work:
-
Wrapping the function to discard the error
85% fail
Silently ignores errors, leading to nil pointer panics
Error Chain
Frequently confused with: