errors

package
v0.0.0-...-599cc13 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package errors provides an errors package for this service. It includes all of the stdlib's functions and types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As(err error, target interface{}) bool

As finds the first error in err's chain that matches target, and if so, sets target to that error value and returns true.

func Is

func Is(err, target error) bool

Is reports whether any error in err's chain matches target.

func Join

func Join(err ...error) error

Join returns an error that wraps the given errors. Any nil error values are discarded. Join returns nil if every value in errs is nil. The error formats as the concatenation of the strings obtained by calling the Error method of each element of errs, with a newline between each string. A non-nil error returned by Join implements the Unwrap() []error method.

func New

func New(text string) error

New returns an error that formats as the given text.

func Unwrap

func Unwrap(err error) error

Unwrap returns the result of calling the Unwrap method on err, if err's type contains an Unwrap method returning error. Otherwise, Unwrap returns nil.

Types

type Category

type Category uint32

Category represents the category of the error.

const (
	// CatUnknown represents an unknown category. This should not be used.
	CatUnknown Category = Category(0) // Unknown
	// CatUser represents an error that is caused by bad user input.
	CatUser Category = Category(1) // User
	// CatInternal represents an internal error.
	CatInternal Category = Category(2) // Internal
)

func (Category) Category

func (c Category) Category() string

func (Category) String

func (i Category) String() string

type EOption

type EOption = errors.EOption

EOption is an optional argument for E().

func WithCallNum

func WithCallNum(i int) EOption

WithCallNum is used if you need to set the runtime.CallNum() in order to get the correct filename and line. This can happen if you create a call wrapper around E(), because you would then need to look up one more stack frame for every wrapper. This defaults to 1 which sets to the frame of the caller of E().

func WithStackTrace

func WithStackTrace() EOption

WithStackTrace will add a stack trace to the error. This is useful for debugging in certain rare cases. This is not recommended for general use as it can cause performance issues when errors are created frequently.

func WithSuppressTraceErr

func WithSuppressTraceErr() EOption

WithSuppressTraceErr will prevent the trace as being recorded with an error status. The trace will still receive the error message. This is useful for errors that are retried and you only want to get a status of error if the error is not resolved.

type Error

type Error = errors.Error

Error is the error type for this service. Error implements github.com/gostdlib/base/errors.E .

func E

func E(ctx context.Context, c errors.Category, t errors.Type, msg error, options ...errors.EOption) Error

E creates a new Error with the given parameters.

type LogAttrer

type LogAttrer = errors.LogAttrer

LogAttrer is an interface that can be implemented by an error to return a list of attributes used in logging.

type Type

type Type uint16

Type represents the type of the error.

const (
	// TypeUnknown represents an unknown type.
	TypeUnknown Type = Type(0) // Unknown
	// TypeBug represents a bug in the calling code. This is only bugs that are known bugs and
	// not because of bad user input. An example would be a switch statement that doesn't cover
	// all cases. The default case should return an error of this type.
	TypeBug Type = Type(1) // Bug
	// TypeParameter represents an error with a parameter that didn't pass validation.
	TypeParameter Type = Type(2) // Parameter
	// TypeConn represents an error with a connection.
	TypeConn Type = Type(3) // Conn
	// TypeTimeout represents a timeout error or cancelation.
	TypeTimeout Type = Type(4) // TimeoutOrCancel
	// TypeFS represents an error with the file system.
	TypeFS Type = Type(5) // FS

	// TypeStorageCreate represents an error with creating storage tables, containers, etc.
	TypeStorageCreate Type = Type(1000) // StorageCreate
	// TypeStorageDelete represents an error with deleting something from storage.
	TypeStorageDelete Type = Type(1001) // StorageDelete
	// TypeStorageGet represents an error with getting something from storage.
	TypeStorageGet Type = Type(1002) // StorageGet
	// TypeStorageList represents an error with listing something from storage.
	TypeStorageList Type = Type(1003) // StorageList
	// TypeStorageUpdate represents an error with updating something in storage.
	TypeStorageUpdate Type = Type(1004) // StorageUpdate
	// TypeStoragePut represents an error with putting something in storage.
	TypeStoragePut Type = Type(1005) // StoragePut
	// TypeStorageClose represents an error with closing storage.
	TypeStorageClose Type = Type(1006) // StorageClose
)

func (Type) String

func (i Type) String() string

func (Type) Type

func (t Type) Type() string

Jump to

Keyboard shortcuts

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