Skip to content

nil-value-with-nil-error

Detect nil payloads returned together with a nil error.

Updated View as Markdown

Default severity: warning

For functions returning a nilable payload and a final error, an explicit nil, nil result makes absence indistinguishable from successful production of a value. Documented APIs that intentionally use this contract can exclude it.

This is an API policy, not a claim that nil, nil is invalid Go. Exclude the check for optional-lookup APIs that deliberately use this convention.

Bad

if value == nil {
	return nil, nil
}
return value, nil

Good

if value == nil {
	return nil, ErrNotFound
}
return value, nil
Navigation

Type to search…

↑↓ navigate↵ selectEsc close