errors

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2021 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package errors supports generic rich error reporting.

This package is deprecated. Since it was written much better approaches have been developed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cause

func Cause(err error) error

Cause returns the initially identified cause of an error if the error is a Chain, or the error itself if it is not.

func Errors

func Errors(err error) []error

Errors returns a flat list of errors in temporal order of annotation. If the provided error is not a Chain a single element slice of error is returned containing the error. If the error implements Links, its Errors method is called and the result returned.

Types

type Chain

type Chain interface {
	// The error behavior of a Chain is based on the last annotation applied.
	error

	// Cause returns the initial error in the Chain.
	Cause() error

	// Link adds an annotation layer to the Chain.
	Link(error) Chain

	// Last returns the Chain, or nil if the Chain is empty, and the most recent annotation.
	Last() (Chain, error)
}

Chain is an error and layered error annotations.

func Last

func Last(err error) (Chain, error)

Last returns the most recent annotation of an error and the remaining chain after the annotation is removed or nil if no further errors remain. Last returns a nil Chain if the error is not a Chain.

func Link(err, annotation error) Chain

Link adds an annotation to an error, returning a Chain.

func NewChain

func NewChain(err error) Chain

NewChain returns a new Chain based on the provided error. If the error is a Chain it is returned unaltered.

type Error

type Error interface {
	// FileLine returns the file name and line number of caller
	// stored at creation of the Error.
	FileLine() (file string, line int)

	// Trace returns a slice continuing the stack trace stored at
	// creation of the Error.
	Trace() (stack []*runtime.Func)

	// Package returns the package name of the stored caller.
	Package() string

	// Function returns the function name of the stored caller.
	Function() string

	// Items returns any items retained by caller.
	Items() []interface{}

	// Tracef returns a formatted stack trace of the error
	// extending depth frames into the stack, 0 indicates no limit.
	Tracef(depth int) string
	error
}

Type Error is the interface for rich error reporting supported by the errors package.

func Make

func Make(message string, skip, depth int, items ...interface{}) Error

Make creates a new Error with message, storing information about the caller stack frame skip levels above the caller and any item that may be needed for handling the error. The number of frames stored is specified by the depth parameter. If depth is zero, Make will panic.

type Links interface {
	Errors() []error // Errors returns a flat list of errors in temporal order of annotation.
}

Links is an optional interface used by the Errors function.

Jump to

Keyboard shortcuts

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