Error Return Value Not Checked

Error return value of `os.Remove` is not checked (errcheck)

Quick Answer

You are ignoring an error return value from a function. Always check errors or explicitly discard them with the blank identifier.

Why This Happens

Go linters like errcheck and golangci-lint flag unchecked error values. Ignoring errors can lead to silent failures, data corruption, and hard-to-debug issues. Always handle errors explicitly, even if you just log them.

The Problem

func cleanup() {
    os.Remove("/tmp/data.txt") // error not checked
    os.Mkdir("/tmp/output", 0755) // error not checked
}

The Fix

func cleanup() error {
    if err := os.Remove("/tmp/data.txt"); err != nil {
        return fmt.Errorf("failed to remove file: %w", err)
    }
    if err := os.Mkdir("/tmp/output", 0755); err != nil {
        return fmt.Errorf("failed to create dir: %w", err)
    }
    return nil
}

Step-by-Step Fix

  1. 1

    Identify the unchecked error

    Find the function call where the error return value is being ignored.

  2. 2

    Capture the error

    Assign the error to a variable and check it with an if statement.

  3. 3

    Handle or propagate

    Either handle the error locally or return it to the caller wrapped with context using fmt.Errorf and %w.

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