errs

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetGRPCErrorContext

func GetGRPCErrorContext(err error) map[string]any

GetGRPCErrorContext extracts the context from a GRPCError if it exists in a joined error chain.

func IsAnyError

func IsAnyError(err error, targets ...error) bool

func Wrap

func Wrap(base, ext error) error

func Wrapf

func Wrapf(base error, str string) error

Types

type Error added in v0.4.0

type Error[T any] interface {
	SetContext(m *map[string]any)
	DefaultError() T
}

type ErrorMapper added in v0.4.0

type ErrorMapper[T Error[T]] struct {
	Errors         []ExposedErrors[T] // Error to mapTo
	PriorityErrors []ExposedErrors[T]
}

func NewMapper added in v0.4.0

func NewMapper[T Error[T]](errors []ExposedErrors[T], priorityErrors []ExposedErrors[T]) ErrorMapper[T]

func (*ErrorMapper[T]) Transform added in v0.4.0

func (m *ErrorMapper[T]) Transform(ctx context.Context, internalErr error) T

Transform has the following rules to find the best match: 1. If error is in priority return the priority one 2. Return ExposedError containing the highest number of errors in err chain 3. If no error found return default

type ExposedErrors added in v0.4.0

type ExposedErrors[T Error[T]] struct {
	InternalErrorChain []error                    // Errors to match on the mapper
	ExposedError       T                          // Can be ApiError, OrbitalError, etc.
	ContextGetter      func(error) map[string]any // Provide context from where the error was obtained
}

type GRPCError

type GRPCError struct {
	Code        GRPCErrorCode
	BaseMessage string
	Reason      string
	Metadata    map[string]string
}

GRPCError represents a structured error for gRPC responses. The error can be matched using errors.Is and errors.As.

func (GRPCError) As

func (e GRPCError) As(target any) bool

func (GRPCError) Error

func (e GRPCError) Error() string

func (GRPCError) FromStatusError

func (e GRPCError) FromStatusError(err error) GRPCError

func (GRPCError) Is

func (e GRPCError) Is(target error) bool

type GRPCErrorCode

type GRPCErrorCode string

type JoinedError

type JoinedError interface {
	Unwrap() []error
}

Jump to

Keyboard shortcuts

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