Canonical guidance

Use when

Avoid

Preferred pattern

func loadConfig(path string) error {
	if err := readConfig(path); err != nil {
		return fmt.Errorf("read config %q: %w", path, err)
	}
	return nil
}

Anti-pattern

Explanation: This anti-pattern is tempting because any formatted message looks clearer, but callers lose reliable inspection when the original error is no longer wrapped.

Why

Related pages

Sources