errorcategory

package
v1.50.7 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package errorcategory attaches stable categories to errors without changing their messages or unwrapping behavior.

Index

Constants

This section is empty.

Variables

View Source
var WrapperTypeName = reflect.TypeOf(categorizedError{}).String()

WrapperTypeName is the Go type name that reflection yields for the wrapper returned by With. Error reporters that derive a title from the concrete error type see this name rather than anything about the underlying failure, so they use it to recognize the wrapper and substitute the category instead.

Functions

func Errorf added in v1.50.1

func Errorf(category Category, format string, args ...any) error

Errorf formats an error with an explicit category.

func New added in v1.50.1

func New(category Category, message string) error

New creates an error with an explicit category.

func UserInputErrorf

func UserInputErrorf(format string, args ...any) error

UserInputErrorf formats an error categorized as UserInput.

func With

func With(err error, category Category) error

With returns an error with an explicit category. A nil error remains nil.

Types

type Categorized

type Categorized interface {
	error
	ErrorCategory() Category
}

Categorized is implemented by errors with an explicit category.

type Category

type Category string

Category identifies the source of an error.

const (
	UserInput  Category = "user_input"
	Auth       Category = "auth"
	Network    Category = "network"
	API        Category = "api"
	RateLimit  Category = "rate_limit"
	Filesystem Category = "filesystem"
	Internal   Category = "internal"
	Panic      Category = "panic"
)

func Get

func Get(err error) (Category, bool)

Get returns the first explicit category in err's unwrap tree.

Jump to

Keyboard shortcuts

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