errtype

package
v0.23.2 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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