errors

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 24, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package errors provides error handling utilities.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound       = errors.New("resource not found")
	ErrInvalidInput   = errors.New("invalid input")
	ErrInternal       = errors.New("internal error")
	ErrUnauthorized   = errors.New("unauthorized")
	ErrForbidden      = errors.New("forbidden")
	ErrUnavailable    = errors.New("service unavailable")
	ErrTimeout        = errors.New("operation timed out")
	ErrNotImplemented = errors.New("not implemented")
)

Standard error types

Functions

func As

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

As finds the first error in err's chain that matches target and sets target to that error value.

func GetContext

func GetContext(err error) logger.Fields

GetContext returns the context of an error. If the error is not a *Error, nil is returned.

func Is

func Is(err error, target error) bool

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

Types

type Category

type Category int

Category represents the category of an error

const (
	// CategoryUnknown is used when the error category is not known
	CategoryUnknown Category = iota
	// CategoryConfiguration is used for configuration-related errors
	CategoryConfiguration
	// CategoryValidation is used for input validation errors
	CategoryValidation
	// CategoryExternal is used for errors from external services
	CategoryExternal
	// CategorySystem is used for system-level errors
	CategorySystem
	// CategoryApplication is used for application-level errors
	CategoryApplication
)

func GetCategory

func GetCategory(err error) Category

GetCategory returns the category of an error. If the error is not a *Error, CategoryUnknown is returned.

func (Category) String

func (c Category) String() string

String returns the string representation of the error category.

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error is a custom error with additional context information.

func New

func New(category Category, msg string) *Error

New creates a new Error with the given category and message.

func Wrap

func Wrap(category Category, err error, msg string) *Error

Wrap wraps an existing error with a category and additional context.

func (*Error) Category

func (e *Error) Category() Category

Category returns the error category.

func (*Error) Context

func (e *Error) Context() logger.Fields

Context returns the error context information.

func (*Error) Error

func (e *Error) Error() string

Error returns the error message.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the wrapped error.

func (*Error) WithContext

func (e *Error) WithContext(key string, value interface{}) *Error

WithContext adds context information to the error.

Jump to

Keyboard shortcuts

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