← 返回 Skills 市场
samber

Golang Error Handling

作者 Samuel Berthe · GitHub ↗ · v1.1.1 · MIT-0
cross-platform ⚠ suspicious
171
总下载
0
收藏
0
当前安装
2
版本数
在 OpenClaw 中安装
/install 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...
使用说明 (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

安全使用建议
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.
功能分析
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.
能力评估
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.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install golang-error-handling
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /golang-error-handling 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
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.
元数据
Slug golang-error-handling
版本 1.1.1
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 2
常见问题

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... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 171 次。

如何安装 Golang Error Handling?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install golang-error-handling」即可一键安装,无需额外配置。

Golang Error Handling 是免费的吗?

是的,Golang Error Handling 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Golang Error Handling 支持哪些平台?

Golang Error Handling 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Golang Error Handling?

由 Samuel Berthe(@samber)开发并维护,当前版本 v1.1.1。

💬 留言讨论