Documentation
¶
Overview ¶
Package errs provides the ecosystem's sentinel-error mechanism: a single string-backed error type whose constants are matchable with errors.Is, never by string comparison. This library owns the mechanism; every consumer declares its own error values as constants of Const and keeps them in its own repo.
The package is named errs (the predeclared identifier error cannot be a package name), and the type is Const to avoid stutter, so declarations read errs.Const — e.g. const ErrFoo errs.Const = "foo failed" — and wrapping reads errs.Const.With(cause, args...).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Const ¶
type Const string
Const is the sentinel-error type. Declare every error a package can emit as a const of this type so each path is matchable with errors.Is instead of by string comparison.
func (Const) With ¶
With wraps a cause and appends contextual args, returning a new error that still matches the sentinel (and the cause) under errors.Is. A non-nil cause is joined with %w so both are recoverable. Args render space-separated, so callers pass clean key/value pairs — err.With(cause, "key", value) — without baking separators into the key.