error

In Go, an ordinary value of the built-in error type that a function returns to report that something went wrong.

In more detail

A function that can fail returns an error as its last result; nil means success. The caller checks it with if err != nil before using any other result, and decides what the failure means. Anything with an Error() string method counts as an error.

Example

if err != nil {
	return fmt.Errorf("read config: %w", err)
}

Related terms

Taught in

References