← Back to Skills Marketplace
samber

Golang Error Handling

by Samuel Berthe · GitHub ↗ · v1.1.1 · MIT-0
cross-platform ⚠ suspicious
171
Downloads
0
Stars
0
Active Installs
2
Versions
Install in OpenClaw
/install golang-error-handling
Description
Idiomatic Golang error handling — creation, wrapping with %w, errors.Is/As, errors.Join, custom error types, sentinel errors, panic/recover, the single handl...
README (SKILL.md)

Persona: You are a Go reliability engineer. You treat every error as an event that must either be handled or propagated with context — silent failures and duplicate logs are equally unacceptable.

Modes:

  • Coding mode — writing new error handling code. Follow the best practices sequentially; optionally launch a background sub-agent to grep for violations in adjacent code (swallowed errors, log-and-return pairs) without blocking the main implementation.
  • Review mode — reviewing a PR's error handling changes. Focus on the diff: check for swallowed errors, missing wrapping context, log-and-return pairs, and panic misuse. Sequential.
  • Audit mode — auditing existing error handling across a codebase. Use up to 5 parallel sub-agents, each targeting an independent category (creation, wrapping, single-handling rule, panic/recover, structured logging).

Community default. A company skill that explicitly supersedes samber/cc-skills-golang@golang-error-handling skill takes precedence.

Go Error Handling Best Practices

This skill guides the creation of robust, idiomatic error handling in Go applications. Follow these principles to write maintainable, debuggable, and production-ready error code.

Best Practices Summary

  1. Returned errors MUST always be checked — NEVER discard with _
  2. Errors MUST be wrapped with context using fmt.Errorf("{context}: %w", err)
  3. Error strings MUST be lowercase, without trailing punctuation
  4. Use %w internally, %v at system boundaries to control error chain exposure
  5. MUST use errors.Is and errors.As instead of direct comparison or type assertion
  6. SHOULD use errors.Join (Go 1.20+) to combine independent errors
  7. Errors MUST be either logged OR returned, NEVER both (single handling rule)
  8. Use sentinel errors for expected conditions, custom types for carrying data
  9. NEVER use panic for expected error conditions — reserve for truly unrecoverable states
  10. SHOULD use slog (Go 1.21+) for structured error logging — not fmt.Println or log.Printf
  11. Use samber/oops for production errors needing stack traces, user/tenant context, or structured attributes
  12. Log HTTP requests with structured middleware capturing method, path, status, and duration
  13. Use log levels to indicate error severity
  14. Never expose technical errors to users — translate internal errors to user-friendly messages, log technical details separately
  15. Keep error messages low-cardinality — don't interpolate variable data (IDs, paths, line numbers) into error strings; attach them as structured attributes instead (via slog at the log site, or via samber/oops .With() on the error itself) so APM/log aggregators (Datadog, Loki, Sentry) can group errors properly

Detailed Reference

  • Error Creation — How to create errors that tell the story: error messages should be lowercase, no punctuation, and describe what happened without prescribing action. Covers sentinel errors (one-time preallocation for performance), custom error types (for carrying rich context), and the decision table for which to use when.

  • Error Wrapping and Inspection — Why fmt.Errorf("{context}: %w", err) beats fmt.Errorf("{context}: %v", err) (chains vs concatenation). How to inspect chains with errors.Is/errors.As for type-safe error handling, and errors.Join for combining independent errors.

  • Error Handling Patterns and Logging — The single handling rule: errors are either logged OR returned, NEVER both (prevents duplicate logs cluttering aggregators). Panic/recover design, samber/oops for production errors, and slog structured logging integration for APM tools.

Parallelizing Error Handling Audits

When auditing error handling across a large codebase, use up to 5 parallel sub-agents (via the Agent tool) — each targets an independent error category:

  • Sub-agent 1: Error creation — validate errors.New/fmt.Errorf usage, low-cardinality messages, custom types
  • Sub-agent 2: Error wrapping — audit %w vs %v, verify errors.Is/errors.As patterns
  • Sub-agent 3: Single handling rule — find log-and-return violations, swallowed errors, discarded errors (_)
  • Sub-agent 4: Panic/recover — audit panic usage, verify recovery at goroutine boundaries
  • Sub-agent 5: Structured logging — verify slog usage at error sites, check for PII in error messages

Cross-References

  • → See samber/cc-skills-golang@golang-samber-oops for full samber/oops API, builder patterns, and logger integration
  • → See samber/cc-skills-golang@golang-observability for structured logging setup, log levels, and request logging middleware
  • → See samber/cc-skills-golang@golang-safety for nil interface trap and nil error comparison pitfalls
  • → See samber/cc-skills-golang@golang-naming for error naming conventions (ErrNotFound, PathError)

References

Usage Guidance
This skill appears to be what it claims (a Go error-handling authoring/audit guide) but with two things to watch for: 1) it explicitly instructs spawning parallel sub-agents to grep and audit your repository — that means the agent will read your project files and may run tooling (grep, go commands). Only enable autonomous invocation if you trust those actions. 2) the documentation contains a small internal inconsistency (an example that interpolates an ID into an error string while other guidance forbids interpolating IDs). Before installing or enabling for autonomous use, review SKILL.md and the references for any parts you don't want automated (search/modify), and consider running the skill in an interactive/manual mode first. If you need higher confidence, ask the skill author for clarification about the inconsistent example and for explicit limits on what the sub-agents will read or modify.
Capability Analysis
Type: OpenClaw Skill Name: golang-error-handling Version: 1.1.1 The skill bundle provides idiomatic and high-quality guidance for Golang error handling, focusing on best practices like structured logging with 'slog', error wrapping with '%w', and the 'single handling rule'. It includes comprehensive reference documentation (references/error-handling.md) and evaluation cases (evals/evals.json) designed to test the agent's adherence to these standards. No indicators of malicious intent, data exfiltration, or unauthorized command execution were found.
Capability Assessment
Purpose & Capability
Name/description match the declared requirements: it's an instruction-only Go error-handling skill that only requires the 'go' binary. Recommending slog and samber/oops is consistent with a production-oriented error-handling skill. However, the documentation contains a contradictory example (an example shows interpolating an ID into an error string while other sections insist on low-cardinality messages and avoiding ID interpolation). This is an internal coherence issue in the docs (not necessarily malicious) and should be clarified.
Instruction Scope
SKILL.md instructs the agent to run audits across codebases and explicitly recommends launching up to 5 parallel sub-agents (Agent tool) to grep for violations. This is within the skill's stated purpose (code audit), but it grants the agent broad discretion to read project files, run grep/other tooling, and spawn background sub-agents. If you don't want automated codebase scanning or background agents, disable autonomous invocation or review the agent actions first.
Install Mechanism
Instruction-only skill with no install spec and no code files. Lowest install risk — nothing is written to disk by an installer. It does recommend third-party Go libraries (samber/oops) for users to adopt in their code, which is expected for this kind of guidance.
Credentials
No environment variables, credentials, or config paths are requested. The single required binary is 'go', which is appropriate for a Go-focused skill.
Persistence & Privilege
always:false (normal). The skill permits autonomous invocation (disable-model-invocation:false), which is the platform default. That combined with the instruction to spawn sub-agents increases the potential blast radius if the agent is allowed to run autonomously, but by itself the skill does not demand persistent or elevated system privileges.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install golang-error-handling
  3. After installation, invoke the skill by name or use /golang-error-handling
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.1.1
- Bumped version to 1.1.1. - Added test coverage configuration: introduced evals/evals.json file. - Updated SKILL.md metadata to reflect the new version. - No changes to core logic or error handling guidance.
v0.1.0
Initial release – idiomatic Go error handling skill: - Documents best practices for error creation, wrapping, inspection, and logging in Go. - Covers custom/sentinel error types, error chain handling, panic/recover use, and the single error handling rule. - Describes structured logging with slog, HTTP middleware for logging requests, and integration with samber/oops. - Introduces three operational modes: Coding, Review, and Audit (with parallel sub-agent support for category-based audits). - Provides cross-references to related Go reliability and observability skills.
Metadata
Slug golang-error-handling
Version 1.1.1
License MIT-0
All-time Installs 0
Active Installs 0
Total Versions 2
Frequently Asked Questions

What is Golang Error Handling?

Idiomatic Golang error handling — creation, wrapping with %w, errors.Is/As, errors.Join, custom error types, sentinel errors, panic/recover, the single handl... It is an AI Agent Skill for Claude Code / OpenClaw, with 171 downloads so far.

How do I install Golang Error Handling?

Run "/install golang-error-handling" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is Golang Error Handling free?

Yes, Golang Error Handling is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does Golang Error Handling support?

Golang Error Handling is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created Golang Error Handling?

It is built and maintained by Samuel Berthe (@samber); the current version is v1.1.1.

💬 Comments