exit

package module
v0.0.0-...-aae6259 Latest Latest
Warning

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

Go to latest
Published: May 22, 2019 License: ISC Imports: 2 Imported by: 24

README

Nifty error handling for Golang

Go Report Card GolangCI

This library provides helper methods to dry up repetitive boilerplate around error checking in Golang.

Instead of:

import "log"

if err != nil {
  log.Fatal(err)
}

you can write:

import "github.com/Originate/exit"

exit.If(err)

The IfWrap and IfWrapf functions wrap the given error into the given error message using errors.Wrap and errors.Wrapf:

exit.IfWrap(err, "something went wrong")
exit.IfWrapf(err, "%s", message)

This makes the most sense for critical errors in Go-based CLI tools, but could be useful elsewhere.

Installation

go get github.com/Originate/exit

A gofix tool to change all compatible usages is available at exitfix.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func If

func If(err error)

If runs log.Fatal with the given error if the given error exists.

func IfWrap

func IfWrap(err error, message string)

IfWrap runs log.Fatal with the given error wrapped in the given message if the error exists.

func IfWrapf

func IfWrapf(err error, format string, formatArgs ...interface{})

IfWrapf runs log.Fatal with the given error wrapped in the given message if the error exists.

Types

This section is empty.

Jump to

Keyboard shortcuts

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