go-error-handling

Installation
SKILL.md

Go Error Handling

Errors are values. Design the type to carry structured context (op, path, cause); callers inspect with errors.Is / errors.As. Panic is for programmer bugs and unrecoverable init — not cross-package flow control.

Structured error types

type PathError struct {
    Op   string   // "open", "unlink"
    Path string
    Err  error    // wrapped cause
}

func (e *PathError) Error() string { return e.Op + " " + e.Path + ": " + e.Err.Error() }
func (e *PathError) Unwrap() error { return e.Err }

Error strings prefix the op/package: "parse config.yaml: line 4: invalid key".

Installs
19
First Seen
Apr 18, 2026