{"modulePath":"github.com/sunvim/utils","version":"v0.1.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package errors\n\nfrom [https://github.com/pkg/errors](https://github.com/pkg/errors) Package errors provides simple error handling primitives.\n\nThe traditional error handling idiom in Go is roughly akin to\n\n\tif err != nil {\n\t        return err\n\t}\n\nwhich when applied recursively up the call stack results in error reports without context or debugging information. The errors package allows programmers to add context to the failure path in their code in a way that does not destroy the original value of the error.\n\n### Adding context to an error {#hdr-Adding_context_to_an_error}\n\nThe errors.Wrap function returns a new error that adds context to the original error by recording a stack trace at the point Wrap is called, together with the supplied message. For example\n\n\t_, err := ioutil.ReadAll(r)\n\tif err != nil {\n\t        return errors.Wrap(err, \"read failed\")\n\t}\n\nIf additional control is required, the errors.WithStack and errors.WithMessage functions destructure errors.Wrap into its component operations: annotating an error with a stack trace and with a message, respectively.\n\n### Retrieving the cause of an error {#hdr-Retrieving_the_cause_of_an_error}\n\nUsing errors.Wrap constructs a stack of errors, adding context to the preceding error. Depending on the nature of the error it may be necessary to reverse the operation of errors.Wrap to retrieve the original error for inspection. Any error value which implements this interface\n\n\ttype causer interface {\n\t        Cause() error\n\t}\n\ncan be inspected by errors.Cause. errors.Cause will recursively retrieve the topmost error that does not implement causer, which is assumed to be the original cause. For example:\n\n\tswitch err := errors.Cause(err).(type) {\n\tcase *MyError:\n\t        // handle specifically\n\tdefault:\n\t        // unknown error\n\t}\n\nAlthough the causer interface is not exported by this package, it is considered a part of its stable public interface.\n\n### Formatted printing of errors {#hdr-Formatted_printing_of_errors}\n\nAll error values returned from this package implement fmt.Formatter and can be formatted by the fmt package. The following verbs are supported:\n\n\t%s    print the error. If the error has a Cause it will be\n\t      printed recursively.\n\t%v    see %s\n\t%+v   extended format. Each Frame of the error's StackTrace will\n\t      be printed in detail.\n\n### Retrieving the stack trace of an error or wrapper {#hdr-Retrieving_the_stack_trace_of_an_error_or_wrapper}\n\nNew, Errorf, Wrap, and Wrapf record a stack trace at the point they are invoked. This information can be retrieved with the following interface:\n\n\ttype stackTracer interface {\n\t        StackTrace() errors.StackTrace\n\t}\n\nThe returned errors.StackTrace type is defined as\n\n\ttype StackTrace []Frame\n\nThe Frame type represents a call site in the stack trace. Frame supports the fmt.Formatter interface that can be used for printing information about the stack trace of this error. For example:\n\n\tif err, ok := err.(stackTracer); ok {\n\t        for _, f := range err.StackTrace() {\n\t                fmt.Printf(\"%+s:%d\", f)\n\t        }\n\t}\n\nAlthough the stackTracer interface is not exported by this package, it is considered a part of its stable public interface.\n\nSee the documentation for Frame.Format for more details.\n\n## Functions\n\n```go\nfunc Cause(err error) error\n```\nCause returns the underlying cause of the error, if possible. An error value has a cause if it implements the following interface:\n\n\ttype causer interface {\n\t       Cause() error\n\t}\n\nIf the error does not implement Cause, the original error will be returned. If the error is nil, nil will be returned without further investigation.\n\n```go\nfunc Errorf(format string, args ...interface{}) error\n```\nErrorf formats according to a format specifier and returns the string as a value that satisfies error. Errorf also records the stack trace at the point it was called.\n\n```go\nfunc New(message string) error\n```\nNew returns an error with the supplied message. New also records the stack trace at the point it was called.\n\n```go\nfunc WithMessage(err error, message string) error\n```\nWithMessage annotates err with a new message. If err is nil, WithMessage returns nil.\n\n```go\nfunc WithMessagef(err error, format string, args ...interface{}) error\n```\nWithMessagef annotates err with the format specifier. If err is nil, WithMessagef returns nil.\n\n```go\nfunc WithStack(err error) error\n```\nWithStack annotates err with a stack trace at the point WithStack was called. If err is nil, WithStack returns nil.\n\n```go\nfunc Wrap(err error, message string) error\n```\nWrap returns an error annotating err with a stack trace at the point Wrap is called, and the supplied message. If err is nil, Wrap returns nil.\n\n```go\nfunc Wrapf(err error, format string, args ...interface{}) error\n```\nWrapf returns an error annotating err with a stack trace at the point Wrapf is called, and the format specifier. If err is nil, Wrapf returns nil.\n\n## Types\n\n```go\ntype Frame uintptr\n```\nFrame represents a program counter inside a stack frame.\n\n```go\nfunc (f Frame) Format(s fmt.State, verb rune)\n```\nFormat formats the frame according to the fmt.Formatter interface.\n\n\t%s    source file\n\t%d    source line\n\t%n    function name\n\t%v    equivalent to %s:%d\n\nFormat accepts flags that alter the printing of some verbs, as follows:\n\n\t%+s   function name and path of source file relative to the compile time\n\t      GOPATH separated by \\n\\t (\u003cfuncname\u003e\\n\\t\u003cpath\u003e)\n\t%+v   equivalent to %+s:%d\n\n```go\ntype StackTrace []Frame\n```\nStackTrace is stack of Frames from innermost (newest) to outermost (oldest).\n\n```go\nfunc (st StackTrace) Format(s fmt.State, verb rune)\n```\nFormat formats the stack of Frames according to the fmt.Formatter interface.\n\n\t%s\tlists source files for each Frame in the stack\n\t%v\tlists the source file and line number for each Frame in the stack\n\nFormat accepts flags that alter the printing of some verbs, as follows:\n\n\t%+v   Prints filename, function, and line number for each Frame in the stack.\n\n","path":"github.com/sunvim/utils/errors","name":"errors","synopsis":"from https://github.com/pkg/errors Package errors provides simple error handling primitives.","isRedistributable":true}
