roninforge/roninforge-go/go-error-wrap
Claude Code and agent skill by roninforge/roninforge-go
- community
Checking that the SKILL.md file is still in the repository.
Convert plain or %v-formatted errors to wrapped errors with %w. Replace == sentinel comparisons with errors.Is. Replace concrete-type checks with errors.As. Define sentinel errors and typed error structs where useful.
Install
npx vskill@latest install roninforge/roninforge-go/go-error-wrapSKILL.md
The same SKILL.md was published earlier as roninforge/roninforge-go/go-error-wrap.
Wrap Go Errors
When to Use
When refactoring a codebase whose error handling does not preserve the chain, or when adding error handling to new code and you want to do it right the first time.
Instructions
- Scan for
fmt.Errorf("...: %v", err)and convert each to%w:
``go // before return fmt.Errorf("load user: %v", err) // after return fmt.Errorf("load user: %w", err) ``
- Scan for
err == X(where X is an exported error) and convert toerrors.Is:
``go // before if err == sql.ErrNoRows { ... } // after if errors.Is(err, sql.ErrNoRows) { ... } ``
- Scan for type assertions on errors and convert to
errors.As:
``go // before if pe, ok := err.(*os.PathError); ok { ... } // after var pe *os.PathError if errors.As(err, &pe) { ... } ``
- Define sentinel errors where callers must distinguish. Place them at the top of the package file:
``go var ( ErrNotFound = errors.New("not found") ErrAlreadyExists = errors.New("already exists") ) ``
- For richer errors, define a struct with
Error()and optionallyUnwrap():
``go type ValidationError struct { Field string Message string } func (e *ValidationError) Error() string { return fmt.Sprintf("%s: %s", e.Field, e.Message) } ``
- For aggregating multiple errors (batch processing, multi-file validation, parallel work), use
errors.Join:
``go var errs []error for _, item := range items { if err := process(item); err != nil { errs = append(errs, fmt.Errorf("%s: %w", item.ID, err)) } } return errors.Join(errs...) ``
- Wrap at boundaries (package edge, layer transition), not at every layer. Each wrap should add meaningful context.
- Never wrap
context.Canceledas an error in HTTP handlers. Treat it as a no-op return.
``go if errors.Is(err, context.Canceled) { return } ``
- After conversion, run
go vet ./...andstaticcheck ./.... Confirm tests still pass.
- Replace
panic(err)calls with a returned error unless the error truly indicates an impossible program state.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/go-error-wrap/SKILL.md
Popularity
- 7-day trend score
- 5
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/roninforge/roninforge-go/go-error-wrap)