errs

package module
v0.3.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 2 Imported by: 0

README

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) Error

func (e Const) Error() string

Error returns the constant's text, implementing the error interface.

func (Const) With

func (e Const) With(err error, args ...any) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL