{"modulePath":"github.com/go-errors/errors","version":"v1.5.1","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package errors\n\nPackage errors provides errors that have stack-traces.\n\nThis is particularly useful when you want to understand the state of execution when an error was returned unexpectedly.\n\nIt provides the type \\*Error which implements the standard golang error interface, so you can use this library interchangably with code that is expecting a normal error return.\n\nFor example:\n\n\tpackage crashy\n\n\timport \"github.com/go-errors/errors\"\n\n\tvar Crashed = errors.Errorf(\"oh dear\")\n\n\tfunc Crash() error {\n\t    return errors.New(Crashed)\n\t}\n\nThis can be called as follows:\n\n\tpackage main\n\n\timport (\n\t    \"crashy\"\n\t    \"fmt\"\n\t    \"github.com/go-errors/errors\"\n\t)\n\n\tfunc main() {\n\t    err := crashy.Crash()\n\t    if err != nil {\n\t        if errors.Is(err, crashy.Crashed) {\n\t            fmt.Println(err.(*errors.Error).ErrorStack())\n\t        } else {\n\t            panic(err)\n\t        }\n\t    }\n\t}\n\nThis package was original written to allow reporting to Bugsnag, but after I found similar packages by Facebook and Dropbox, it was moved to one canonical location so everyone can benefit.\n\n## Variables\n\n```go\nvar MaxStackDepth = 50\n```\nThe maximum number of stackframes on any error.\n\n## Functions\n\n```go\nfunc As(err error, target interface{}) bool\n```\nAs finds the first error in err's tree that matches target, and if one is found, sets target to that error value and returns true. Otherwise, it returns false.\n\nFor more information see stdlib errors.As.\n\n```go\nfunc Is(e error, original error) bool\n```\nIs detects whether the error is equal to a given error. Errors are considered equal by this function if they are matched by errors.Is or if their contained errors are matched through errors.Is.\n\n```go\nfunc Join(errs ...error) error\n```\nJoin returns an error that wraps the given errors. Any nil error values are discarded. Join returns nil if every value in errs is nil. The error formats as the concatenation of the strings obtained by calling the Error method of each element of errs, with a newline between each string.\n\nA non-nil error returned by Join implements the Unwrap() \\[]error method.\n\nFor more information see stdlib errors.Join.\n\n```go\nfunc Unwrap(err error) error\n```\nUnwrap returns the result of calling the Unwrap method on err, if err's type contains an Unwrap method returning error. Otherwise, Unwrap returns nil.\n\nUnwrap only calls a method of the form \"Unwrap() error\". In particular Unwrap does not unwrap errors returned by [Join](#Join).\n\nFor more information see stdlib errors.Unwrap.\n\n## Types\n\n```go\ntype Error struct {\n\tErr error\n\t// contains filtered or unexported fields\n}\n```\nError is an error with an attached stacktrace. It can be used wherever the builtin error interface is expected.\n\n```go\nfunc Errorf(format string, a ...interface{}) *Error\n```\nErrorf creates a new error with the given message. You can use it as a drop-in replacement for fmt.Errorf() to provide descriptive errors in return values.\n\n```go\nfunc New(e interface{}) *Error\n```\nNew makes an Error from the given value. If that value is already an error then it will be used directly, if not, it will be passed to fmt.Errorf(\"%v\"). The stacktrace will point to the line of code that called New.\n\n```go\nfunc ParsePanic(text string) (*Error, error)\n```\nParsePanic allows you to get an error object from the output of a go program that panicked. This is particularly useful with [https://github.com/mitchellh/panicwrap](https://github.com/mitchellh/panicwrap).\n\n```go\nfunc Wrap(e interface{}, skip int) *Error\n```\nWrap makes an Error from the given value. If that value is already an error then it will be used directly, if not, it will be passed to fmt.Errorf(\"%v\"). The skip parameter indicates how far up the stack to start the stacktrace. 0 is from the current call, 1 from its caller, etc.\n\n```go\nfunc WrapPrefix(e interface{}, prefix string, skip int) *Error\n```\nWrapPrefix makes an Error from the given value. If that value is already an error then it will be used directly, if not, it will be passed to fmt.Errorf(\"%v\"). The prefix parameter is used to add a prefix to the error message when calling Error(). The skip parameter indicates how far up the stack to start the stacktrace. 0 is from the current call, 1 from its caller, etc.\n\n```go\nfunc (err *Error) Callers() []uintptr\n```\nCallers satisfies the bugsnag ErrorWithCallerS() interface so that the stack can be read out.\n\n```go\nfunc (err *Error) Error() string\n```\nError returns the underlying error's message.\n\n```go\nfunc (err *Error) ErrorStack() string\n```\nErrorStack returns a string that contains both the error message and the callstack.\n\n```go\nfunc (err *Error) Stack() []byte\n```\nStack returns the callstack formatted the same way that go does in runtime/debug.Stack()\n\n```go\nfunc (err *Error) StackFrames() []StackFrame\n```\nStackFrames returns an array of frames containing information about the stack.\n\n```go\nfunc (err *Error) TypeName() string\n```\nTypeName returns the type this error. e.g. \\*errors.stringError.\n\n```go\nfunc (err *Error) Unwrap() error\n```\nReturn the wrapped error (implements api for As function).\n\n```go\ntype StackFrame struct {\n\t// The path to the file containing this ProgramCounter\n\tFile string\n\t// The LineNumber in that file\n\tLineNumber int\n\t// The Name of the function that contains this ProgramCounter\n\tName string\n\t// The Package that contains this function\n\tPackage string\n\t// The underlying ProgramCounter\n\tProgramCounter uintptr\n}\n```\nA StackFrame contains all necessary information about to generate a line in a callstack.\n\n```go\nfunc NewStackFrame(pc uintptr) (frame StackFrame)\n```\nNewStackFrame popoulates a stack frame object from the program counter.\n\n```go\nfunc (frame *StackFrame) Func() *runtime.Func\n```\nFunc returns the function that contained this frame.\n\n```go\nfunc (frame *StackFrame) SourceLine() (string, error)\n```\nSourceLine gets the line of code (from File and Line) of the original source if possible.\n\n```go\nfunc (frame *StackFrame) String() string\n```\nString returns the stackframe formatted in the same way as go does in runtime/debug.Stack()\n\n","path":"github.com/go-errors/errors","name":"errors","synopsis":"Package errors provides errors that have stack-traces.","isRedistributable":true}
