1. Habit
  2. Skills
  3. Golang Error Handling skill
samber · 43K installs

Golang Error Handling skill
Runs by itself, PR changes Go files.

No swallowed or double-logged errors.

Install the Golang Error Handling skill and make it a habit: follow https://gethabit.dev/skills/samber/golang-error-handling.md

  1. 1Copy
  2. 2Paste into Claude Code, Codex or Cursor
  3. 3It runs by itself

43K installs4K starsMIT licenceSource on GitHub ↗

Golang Error Handling

by samber · 43K installs

The skill

The golang error handling skill teaches Go developers idiomatic error handling: wrapping with %w, errors.Is and errors.As, errors.Join, sentinel and custom errors, panic and recover, and structured logging with slog.

Only when you ask.

The habit

No swallowed or double-logged errors.

↻ Runs by itselfPR changes Go files

How the habit works.
You don't have to.

Three questionsWhen does it start? How does it check its work? What does it remember?

One run, step by step.
Then it stops.

Stop ruleStops after one pull request per run.

  1. 01

    Read the diff

    The agent lists changed Go functions that create, wrap, log or return errors.

  2. 02

    Check creation

    It checks errors.New and fmt.Errorf use, lowercase messages and sentinel versus custom types.

  3. 03

    Check wrapping

    It checks %w inside the code, %v at system boundaries, and errors.Is or errors.As for inspection.

  4. 04

    Check single handling

    It finds log-and-return pairs, swallowed errors and errors discarded with _.

  5. 05

    Check panic and logging

    It flags panic for expected cases and logging without slog.

  6. 06

    Run lint and tests

    It runs golangci-lint and the tests, comments findings and logs them.

What it may do.
Nothing more.

Safe by defaultIt writes only in its own folder and asks you before anything goes out.

Is it for you?
Use it when it fits.

Quick checkRead both lists. If the left one sounds like you, the Golang Error Handling skill helps.

Use it when

  • ✓ You write or review Go error handling
  • ✓ Your logs show duplicate errors
  • ✓ You add structured logging with slog

Skip it when

  • – You need the full samber/oops API
  • – Your project is not Go

Questions

Golang Error Handling skill, answered.

What is the single handling rule?

An error is either logged or returned, never both, so logs do not fill with duplicates.

Can it audit the whole codebase?

Yes. Audit mode uses up to 5 sub-agents, one per error category. This loop uses review mode on each PR.

Does it need samber/oops?

No. The skill suggests samber/oops for production errors that need stack traces, but the checks work without it.

How do I install the Golang Error Handling skill?

Copy the prompt at the top into your agent. It installs the skill from samber/cc-skills-golang and sets up the habit. Or run npx skills add samber/cc-skills-golang --skill golang-error-handling.

Is the Golang Error Handling skill free?

Yes. It is published under MIT. Habit is free too.

Golang Error Handling. Now as a habit.

Install the Golang Error Handling skill and make it a habit: follow https://gethabit.dev/skills/samber/golang-error-handling.md

  • Free
  • No account
  • Undo in one line

All samber skills →More code skills →

Works in

  • Claude Code
  • Codex
  • Cursor
  • ChatGPT
  • Claude app

Made by samber, published under MIT. Habit links to the original and never changes it. Is this your skill?

Copying didn't work here. Select the line and copy it by hand.