Multiple-Value in Single-Value Context

multiple-value os.Open() (value of type (*os.File, error)) used in single-value context

Quick Answer

The function returns multiple values but you are only capturing one. Assign all return values or use the blank identifier to discard unwanted ones.

Why This Happens

Many Go functions return a value and an error. You must capture both return values. You cannot pass a multi-value return directly to a function that expects a single argument or assign it to a single variable.

The Problem

func main() {
    f := os.Open("file.txt") // os.Open returns (*File, error)
    defer f.Close()
}

The Fix

func main() {
    f, err := os.Open("file.txt")
    if err != nil {
        log.Fatal(err)
    }
    defer f.Close()
}

Step-by-Step Fix

  1. 1

    Identify the multi-value function

    Check the function signature to see how many values it returns.

  2. 2

    Capture all return values

    Use := with the correct number of variables on the left side.

  3. 3

    Handle the error

    Check the error value and handle it appropriately. Use _ to discard if you intentionally want to ignore it.

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free