Use `fmt.Errorf` with `%w`: ```go if err != nil { return fmt.Errorf("failed to load config: %w", err) } ``` That adds context while preserving the original error in the chain, so callers can still do: ```go if errors.Is(err, os.ErrNotExist) { // handle missing file } var pathErr *os.PathError if errors.As(err, &pathErr) { // handle typed error } ``` Use `%w` when wrapping. If you use `%v` or `%s`, callers cannot reliably check the original error with `errors.Is` or `errors.As`.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Golang Error Handling?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-golang-error-handling-agent-skills-standard)
Use `fmt.Errorf` with `%w`:
```go
if err != nil {
return fmt.Errorf("failed to load config: %w", err)
}
```
That adds context while preserving the original error in the chain, so callers can still do:
```go
if errors.Is(err, os.ErrNotExist) {
// handle missing file
}
var pathErr *os.PathError
if errors.As(err, &pathErr) {
// handle typed error
}
```
Use `%w` when wrapping. If you use `%v` or `%s`, callers cannot reliably check the original error with `errors.Is` or `errors.As`.