{"modulePath":"github.com/hra42/errors","version":"v1.0.4","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package errors\n\nPackage errors defines error types used across Lantern project.\n\n\tn, err := Foo()\n\tif err != nil {\n\t    return n, errors.New(\"Unable to do Foo: %v\", err)\n\t}\n\nor\n\n\t  n, err := Foo()\n\t\treturn n, errors.Wrap(err)\n\nNew() method will create a new error with err as its cause. Wrap will wrap err, returning nil if err is nil.  If err is an error from Go's standard library, errors will extract details from that error, at least the Go type name and the return value of err.Error().\n\nOne can record the operation on which the error occurred using Op():\n\n\treturn n, errors.New(\"Unable to do Foo: %v\", err).Op(\"FooDooer\")\n\nOne can also record additional data:\n\n\t  return n, errors.\n\t\t\tNew(\"Unable to do Foo: %v\", err).\n\t\t\tOp(\"FooDooer\").\n\t\t\tWith(\"mydata\", \"myvalue\").\n\t\t\tWith(\"moredata\", 5)\n\nWhen used with github.com/getlantern/ops, Error captures its current context and propagates that data for use in calling layers.\n\nWhen used with github.com/getlantern/golog, Error provides stacktraces:\n\n\tHello World\n\t\tat github.com/getlantern/errors.TestNewWithCause (errors_test.go:999)\n\t\tat testing.tRunner (testing.go:999)\n\t\tat runtime.goexit (asm_amd999.s:999)\n\tCaused by: World\n\t\tat github.com/getlantern/errors.buildCause (errors_test.go:999)\n\t\tat github.com/getlantern/errors.TestNewWithCause (errors_test.go:999)\n\t\tat testing.tRunner (testing.go:999)\n\t\tat runtime.goexit (asm_amd999.s:999)\n\tCaused by: orld\n\tCaused by: ld\n\t\tat github.com/getlantern/errors.buildSubSubCause (errors_test.go:999)\n\t\tat github.com/getlantern/errors.buildSubCause (errors_test.go:999)\n\t\tat github.com/getlantern/errors.buildCause (errors_test.go:999)\n\t\tat github.com/getlantern/errors.TestNewWithCause (errors_test.go:999)\n\t\tat testing.tRunner (testing.go:999)\n\t\tat runtime.goexit (asm_amd999.s:999)\n\tCaused by: d\n\nIt's the caller's responsibility to avoid race conditions accessing the same error instance from multiple goroutines.\n\n## Types\n\n```go\ntype Error interface {\n\terror\n\tcontext.Contextual\n\n\t// ErrorClean returns a non-parameterized version of the error whenever\n\t// possible. For example, if the error text is:\n\t//\n\t//     unable to dial www.google.com caused by: i/o timeout\n\t//\n\t// ErrorClean might return:\n\t//\n\t//     unable to dial %v caused by: %v\n\t//\n\t// This can be useful when performing analytics on the error.\n\tErrorClean() string\n\n\t// MultiLinePrinter implements the interface golog.MultiLine\n\tMultiLinePrinter() func(buf *bytes.Buffer) bool\n\n\t// Op attaches a hint of the operation triggers this Error. Many error types\n\t// returned by net and os package have Op pre-filled.\n\tOp(op string) Error\n\n\t// With attaches arbitrary field to the error. keys will be normalized as\n\t// underscore_divided_words, so all characters except letters and numbers will\n\t// be replaced with underscores, and all letters will be lowercased.\n\tWith(key string, value interface{}) Error\n\n\t// RootCause returns the bottom-most cause of this Error. If the Error\n\t// resulted from wrapping a plain error, the wrapped error will be returned as\n\t// the cause.\n\tRootCause() error\n}\n```\nError wraps system and application defined errors in unified structure for reporting and logging. It's not meant to be created directly. User New(), Wrap() and Report() instead.\n\n```go\nfunc New(desc string, args ...interface{}) Error\n```\nNew creates an Error with supplied description and format arguments to the description. If any of the arguments is an error, we use that as the cause.\n\n```go\nfunc NewOffset(offset int, desc string, args ...interface{}) Error\n```\nNewOffset is like New but offsets the stack by the given offset. This is useful for utilities like golog that may create errors on behalf of others.\n\n```go\nfunc Wrap(err error) Error\n```\nWrap creates an Error based on the information in an error instance.  It returns nil if the error passed in is nil, so we can simply call errors.Wrap(s.l.Close()) regardless there's an error or not. If the error is already wrapped, it is returned as is.\n\n","path":"github.com/hra42/errors","name":"errors","synopsis":"Package errors defines error types used across Lantern project.","isRedistributable":true}
