errorhelper

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: MIT Imports: 6 Imported by: 5

README

errorhelper

Go Reference

Helpers for Go's error.

Documentation

Overview

Package errorhelper contains error-related helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CallerError added in v0.6.0

func CallerError(err error) error

CallerError prepends the provided error with caller function name.

func Must added in v0.2.0

func Must[R any](r R, err error) R

Must returns 'r' if 'err' is nil. Otherwise, it panics with 'err'.

func Must0 added in v0.3.0

func Must0(err error)

Must0 panics with 'err', if 'err' is not nil.

func Must2 added in v0.5.0

func Must2[R1, R2 any](r1 R1, r2 R2, err error) (R1, R2)

Must2 returns ('r1', 'r2') if 'err' is nil. Otherwise, it panics with 'err'.

func PanicToError added in v0.4.0

func PanicToError(panicArg any, err *error)

PanicToError converts panic to error in the following way:

PanicToError must be called from a defer statement:

func Example() (err error) {
  defer func() {
    PanicToError(recover(), &err)
  }()
  return nil
}

(See tests.)

func UnwrapErrors

func UnwrapErrors(err error) []error

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

Types

This section is empty.

Jump to

Keyboard shortcuts

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