Canonical guidance

Use when

Avoid

Preferred pattern

if errors.Is(err, context.DeadlineExceeded) {
	return retryLater()
}

var pathErr *fs.PathError
if errors.As(err, &pathErr) {
	log.Printf("path failed: %s", pathErr.Path)
}

Anti-pattern

Explanation: This anti-pattern is tempting because direct equality and type assertions are simple, but they break as soon as wrapping enters the picture.

Why

Related pages

Sources