Help us shape the future of Go! Take the 2026 Go Developer Survey

errtype

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package errtype classifies errors into low-cardinality names for the error.type telemetry attribute. The name never contains error text, which can carry keys, values, or query arguments. Context cancellation classes win over owner-supplied sentinels; otherwise callers receive a matched name or the innermost Go type, never Error().

Example: class := errtype.Of(context.DeadlineExceeded); fmt.Println(class)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Of

func Of(err error, known ...Sentinel) string

Of returns the name of err's class: the Name of the first matching sentinel in known (after the context errors), otherwise the Go type of the innermost error in its Unwrap chain, such as "*pgconn.PgError". It returns "" for a nil err. It reads error chains synchronously; custom Is and Unwrap implementations must obey the ordinary errors package's contracts.

Example: fmt.Println(errtype.Of(fmt.Errorf("receive: %w", context.Canceled)))

Types

type Sentinel

type Sentinel struct {
	// Err is the error to match.
	// Example: known := errtype.Sentinel{Err: context.Canceled, Name: "canceled"}; _ = known
	Err error

	// Name is the value reported when Err matches.
	// Example: known := errtype.Sentinel{Err: context.Canceled, Name: "canceled"}; fmt.Println(known.Name)
	Name string
}

Sentinel names an error that callers match with errors.Is. Names must be static, bounded classifications, not interpolated error text. Of checks supplied entries in order after the common context errors.

missing := errors.New("object missing")
class := errtype.Of(missing, errtype.Sentinel{Err: missing, Name: "storage.ErrNotFound"})
fmt.Println(class)

Jump to

Keyboard shortcuts

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