nil pointer dereference

Trying to follow a pointer that is nil, which makes a Go program panic with an invalid memory address error.

An unchecked nil pointer crashes the whole process, taking down every request it was serving.

In more detail

It is one of the most common Go crashes, usually from an optional value or a failed call whose result was used without checking the error. Check if p == nil before using *p, or design so the zero value is useful and no pointer is needed.

Example

if value == nil {
	return
}
fmt.Println(*value)

Related terms

Taught in

References