go-error-wrap
Skill0 starsChanged 7 months agoMITView on GitHub
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.
In this repository3 other files it gives its agents.
- go-modernizeSkill
- go-new-serviceSkill
- go-validateSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 10
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 …
- Very specific: line 77
Never wrap context.Canceled as an error in HTTP handlers.
- Very specific: line 83
After conversion, run go vet ./...
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
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:// 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:// before if err == sql.ErrNoRows { ... } // after if errors.Is(err, sql.ErrNoRows) { ... }Scan for type assertions on errors and convert to
errors.As:// 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:
var ( ErrNotFound = errors.New("not found") ErrAlreadyExists = errors.New("already exists") )For richer errors, define a struct with
Error()and optionallyUnwrap():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: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.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.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

