errors

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: GPL-3.0 Imports: 3 Imported by: 0

README

errors

Import path: github.com/InsideGallery/core/errors

Overview

errors provides compatibility helpers for building and combining errors while preserving errors.Is and errors.As checks across a cause/effect pair.

Main APIs

  • New(text string) delegates to the standard library error constructor.
  • Wrap(cause, effect error) combines two distinct errors into MultipleError.
  • Wrapf(err error, format string, args ...any) adds formatted context to an existing error.
  • Combine(errs ...error) folds several errors into one.
  • MultipleError stores Cause and Effect, joins messages with ": ", unwraps to Cause, and checks both sides in Is and As.
  • BoundaryError and WrapBoundary(kind, operation, err) wrap infrastructure or SDK errors at package boundaries.

Usage

var closeErr error
var writeErr error

err := coreerrors.Combine(writeErr, closeErr)
if err != nil && errors.Is(err, closeErr) {
	return err
}

Notes

Import this package with an alias such as coreerrors when the standard library errors package is also used. Wrap returns nil when both inputs are nil, returns the non-nil input when only one exists, and deduplicates two errors with the same message by returning the cause.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Combine

func Combine(errs ...error) (err error)

Combine receive multiple errors and return one

func New

func New(text string) error

New return new error

func Wrap

func Wrap(cause error, effect error) error

Wrap wrap error with error

func WrapBoundary added in v1.1.0

func WrapBoundary(kind string, operation string, err error) error

WrapBoundary returns nil for nil errors or a BoundaryError for non-nil errors.

func Wrapf

func Wrapf(err error, format string, args ...any) error

Wrapf wrap by format

Types

type BoundaryError added in v1.1.0

type BoundaryError struct {
	Kind      string
	Operation string
	Err       error
}

BoundaryError wraps an infrastructure or SDK error at a core-owned package boundary.

func (BoundaryError) Error added in v1.1.0

func (e BoundaryError) Error() string

Error returns the boundary error message.

func (BoundaryError) Unwrap added in v1.1.0

func (e BoundaryError) Unwrap() error

Unwrap returns the wrapped SDK or infrastructure error.

type MultipleError

type MultipleError struct {
	Cause  error
	Effect error
}

MultipleError type for wrap error around error

func (MultipleError) As

func (s MultipleError) As(target any) 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. Otherwise, it returns false.

func (MultipleError) Error

func (s MultipleError) Error() string

Error return strings based on error

func (MultipleError) Is

func (s MultipleError) Is(err error) bool

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

func (MultipleError) Unwrap

func (s MultipleError) Unwrap() error

Jump to

Keyboard shortcuts

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