roninforge/roninforge-go/go-error-wrap

Claude Code and agent skill by roninforge/roninforge-go

Trust tier 3
  • community
Source check pending

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-wrap

SKILL.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

  1. 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) ``

  1. Scan for err == X (where X is an exported error) and convert to errors.Is:

``go // before if err == sql.ErrNoRows { ... } // after if errors.Is(err, sql.ErrNoRows) { ... } ``

  1. 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) { ... } ``

  1. 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") ) ``

  1. For richer errors, define a struct with Error() and optionally Unwrap():

``go type ValidationError struct { Field string Message string } func (e *ValidationError) Error() string { return fmt.Sprintf("%s: %s", e.Field, e.Message) } ``

  1. 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...) ``

  1. Wrap at boundaries (package edge, layer transition), not at every layer. Each wrap should add meaningful context.
  1. Never wrap context.Canceled as an error in HTTP handlers. Treat it as a no-op return.

``go if errors.Is(err, context.Canceled) { return } ``

  1. After conversion, run go vet ./... and staticcheck ./.... Confirm tests still pass.
  1. 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

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
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/roninforge/roninforge-go/go-error-wrap/badge)](https://verified-skill.com/skills/roninforge/roninforge-go/go-error-wrap)

Something wrong with this skill or its page? Tell us.