npx claudepluginhub jamesprial/prial-plugins --plugin golang-workflowThis skill uses the workspace's default tool permissions.
Use `fmt.Errorf` with `%w` to add context while preserving the error chain.
Guides Go error handling: sentinels vs custom types, fmt.Errorf wrapping (%w/%v), error flow, propagation across packages, errors.Is/As, with anti-pattern checker script.
Provides Go error handling patterns: wrapping with %w, sentinel errors, custom types, errors.Is/As. Use for implementing, designing error types, debugging chains, reviewing code.
Provides Go error handling patterns: basic errors, wrapping with %w, sentinel errors, custom types, errors.Is, and Unwrap for robust apps.
Share bugs, ideas, or general feedback.
Use fmt.Errorf with %w to add context while preserving the error chain.
func ReadConfig(path string) (*Config, error) {
data, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("read config %s: %w", path, err)
}
var cfg Config
if err := json.Unmarshal(data, &cfg); err != nil {
return nil, fmt.Errorf("parse config %s: %w", path, err)
}
return &cfg, nil
}
// Bad: Loses error chain
return nil, fmt.Errorf("read config failed: %v", err)
// Bad: No context
return nil, err
// Bad: String concatenation
return nil, errors.New("read config: " + err.Error())
%w to wrap, not %v or %s// Error flows up with context at each layer:
// "process user 123: read config /etc/app.conf: open /etc/app.conf: no such file or directory"
func ProcessUser(id int) error {
cfg, err := ReadConfig("/etc/app.conf")
if err != nil {
return fmt.Errorf("process user %d: %w", id, err)
}
// use cfg...
return nil
}