Error Result Position

ID

go.error_last_return

Severity

info

Remediation Complexity

simple

Remediation Risk

medium

Remediation Effort

low

Resource

Naming Convention

Language

Go

Tags

naming

Description

Reports a function or method whose result tuple contains an error result that is not in the last position.

Rationale

The pervasive Go convention is to return the error last ((value, error)), so every call site relies on the same shape: v, err := f(). An error placed earlier forces readers and tooling to special-case the function and breaks the if err != nil muscle memory.

// Bad
func read() (error, int) { return nil, 0 } // FLAW

// Good
func read() (int, error) { return 0, nil } // OK
func close() error { return nil }          // OK — single result

Remediation

Reorder the results so the error value comes last.