warning

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2020 License: BSD-3-Clause Imports: 2 Imported by: 12

README

warning GoDoc Go Report Card

Package warning provides a simple way to handle errors that should not stop execution (return err), but rather continue.

go get github.com/lunemec/warning

Common Go idiom is this:

if err != nil {
    return err
}

But what if you wanted to distinguish between error that ends execution and error that should just be logged? This package provides you with just that.

if err != nil && !warning.IsWarning(err) {
	//This is executed only if err is not a warning.
	return
}

It also works well with https://github.com/pkg/errors and https://github.com/hashicorp/go-multierror.

Documentation

Overview

Package warning provides a simple way to handle errors that should not stop execution (return err), but rather continue.

Common Go idiom is this:

if err != nil {
	return err
}

But what if you wanted to distinguish between error that ends execution and error that should just be logged? This package provides you with just that.

if err != nil && warning.IsWarning(err) {
	// This is executed only if err is not a warning.
	return
}

It also works well with https://github.com/pkg/errors and https://github.com/hashicorp/go-multierror.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsWarning

func IsWarning(err error) bool

IsWarning returns true if given error is Warning type.

func New

func New(message string) error

New creates new Warning from a message.

func Wrap

func Wrap(err error) error

Wrap wraps any error into Warning.

Types

type Warning

type Warning struct {
	// contains filtered or unexported fields
}

Warning type wraps error interface. This type is used to represent error that should not cause stopping of execution, but just be logged and continue.

func (*Warning) Cause

func (w *Warning) Cause() error

Cause returns the underlying cause of Warning.

Jump to

Keyboard shortcuts

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