errors

package module
v0.0.0-...-8ebd5bc Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2019 License: MIT Imports: 1 Imported by: 10

README

errors

A small error library that augments the errors library in go standard library.

Documentation

Overview

Example
package main

import "github.com/gdey/errors"

// ErrSentinel is an example of a sentinel errors that is a constants
const ErrSentinel = errors.String("sentinel")

func aOops() error {
	return ErrSentinel
}

func bOops() error {
	return errors.Wrap(aOops(), "error calling a")

}

func main() {
	var err error = errors.Wrap(ErrSentinel, "top wrap")
	_ = err
}
Output:

Index

Examples

Constants

View Source
const ErrCanceled = String("cancelled")

Canceled is used as a sentinel error to allow things to state that the operation was cancelled.

View Source
const ErrNilObject = String("nil receiver object")

NilObject is used as a sentinel error to allow things to state that the receiver object of the method is nil

Variables

This section is empty.

Functions

func Root

func Root(err error) (nerr error, count int)

Root will walk the error graph returning the top Most error and count.

func Walk

func Walk(err error, fn func(err error) bool)

Walk each error in the list of error calling fn. If fn returns false stop the walk.

Types

type Err

type Err interface {
	// Error is the human readable version of the error.
	// the main use should be for log files and printing
	// on screen. To compare errors use IsEqual.
	Error() string
	// Cause should return the error that this error wraps
	// if it wraps an error, or nil.
	Cause() error
}

func Wrap

func Wrap(err error, description string) Err

Wrap wraps the error with the given description and returns a new Err object

func Wrapf

func Wrapf(err error, description string, data ...interface{}) Err

Wrapf wraps the error with the given description and returns a new Err object

type String

type String string

String is an error type that can be a constant.

func (String) Cause

func (str String) Cause() error

func (String) Error

func (str String) Error() string

Jump to

Keyboard shortcuts

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