goadapt

package module
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2021 License: LGPL-2.1 Imports: 6 Imported by: 34

README

goadapt

Use the Ck/Return pattern from this package to replace the common if err != nil {return err} boilerplate.

  • Allows shorter, more readable code.
  • Provides more descriptive error messages.
  • Includes file name and line number in error strings by default.
  • Allows optional per-error and per-function annotations.
  • Allows optional format strings for annotations.

Inspired in part by Dave Cheney's https://github.com/pkg/errors and Harri Lainio's https://github.com/lainio/err2.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Assert

func Assert(cond bool, args ...interface{})

Assert takes a bool and zero or more arguments. If the bool is true, then Assert returns. If the boolean is false, then Assert panics. The panic is of type adaptErr. The adaptErr contains the filename and line number of the caller. The first argument is used as a Sprintf() format string. Any remaining arguments are provided to the Sprintf() as values. The Sprintf() result is stored as adaptErr.msg, to be used later in the adaptErr.Error() string.

func Ck

func Ck(err error, args ...interface{})

func ErrnoIf added in v0.0.9

func ErrnoIf(cond bool, errno syscall.Errno, args ...interface{})

ErrnoIf takes a bool and zero or more arguments. If the bool is false, then ErrnoIf returns. If the boolean is true, then ErrnoIf panics. The panic is of type adaptErr. The adaptErr contains the filename and line number of the caller. The first argument must be of type syscall.Errno; the adaptErr wraps the errno. The next argument is used as a Sprintf() format string. Any remaining arguments are provided to the Sprintf() as values. The Sprintf() result is stored as adaptErr.msg, to be used later in the adaptErr.Error() string.

func ExitIf added in v0.0.5

func ExitIf(err, target error, args ...interface{})

func Halt added in v0.0.8

func Halt(rc *int, msg *string)

convert panic into returned rc and msg

func Info

func Info(msg interface{}, args ...interface{})

func Return

func Return(err *error, args ...interface{})

convert panic into returned err see https://github.com/lainio/err2 and https://blog.golang.org/go1.13-errors

func ReturnChan added in v0.0.10

func ReturnChan(errc chan error, args ...interface{})

convert panic into returned err on channel

func Uerr

func Uerr(msg interface{}, args ...interface{})

func Unpanic added in v0.0.11

func Unpanic(errno *syscall.Errno, logfunc func(msg string))

Unpanic converts a panic into a syscall.Errno and a message.

Types

This section is empty.

Jump to

Keyboard shortcuts

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