{"modulePath":"github.com/cockroachdb/errors","version":"v1.14.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package errors\n\n## Constants\n\n```go\nconst UnimplementedErrorHint = issuelink.UnimplementedErrorHint\n```\nUnimplementedErrorHint is the hint emitted upon unimplemented errors.\n\n## Variables\n\n```go\nvar ErrUnsupported = errors.ErrUnsupported\n```\nErrUnsupported indicates that a requested operation cannot be performed, because it is unsupported. This is the same value as the standard library's errors.ErrUnsupported, re-exported here for drop-in compatibility.\n\n## Functions\n\n```go\nfunc As(err error, target interface{}) bool\n```\nAs finds the first error in err's chain that matches the type to which target points, and if so, sets the target to its value and returns true. An error matches a type if it is assignable to the target type, or if it has a method As(interface{}) bool such that As(target) returns true. As will panic if target is not a non-nil pointer to a type which implements error or is of interface type.\n\nThe As method should set the target to its value and return true if err matches the type to which target points.\n\nNote: this implementation differs from that of xerrors as follows: - it also supports recursing through causes with Cause(). - if it detects an API use error, its panic object is a valid error.\n\n```go\nfunc AssertionFailedWithDepthf(depth int, format string, args ...interface{}) error\n```\nAssertionFailedWithDepthf creates an internal error with a stack trace collected at the specified depth. See the doc of \\`AssertionFailedf()\\` for more details.\n\n```go\nfunc AssertionFailedf(format string, args ...interface{}) error\n```\nAssertionFailedf creates an internal error.\n\nDetail is shown: - via \\`errors.GetSafeDetails()\\`, shows redacted strings. - when formatting with \\`%+v\\`. - in Sentry reports.\n\n```go\nfunc BuildSentryReport(err error) (*sentry.Event, map[string]interface{})\n```\nBuildSentryReport builds the components of a sentry report.  This can be used instead of ReportError() below to use additional custom conditions in the reporting or add additional reporting tags.\n\nThe Sentry Event is populated for maximal utility when exploited in the Sentry.io web interface and database.\n\nA Sentry report is displayed visually in the Sentry UI as follows:\n\n////////////// Title: (1) some prefix in bold (2) one line for a stack trace (3) a single-line subtitle\n\n(4) the tags, as a tag soup (concatenated in a single paragraph, unsorted)\n\n(5) a \"message\"\n\n(6) zero or more \"exceptions\", each composed of:\n\n\t(7) a bold title\n\t(8) some freeform text\n\t(9) a stack trace\n\n(10) metadata fields: environment, arch, etc\n\n(11) \"Additional data\" fields\n\n(12) SDK version ///////////////\n\nThese visual items map to the Sentry Event object as follows:\n\n(1) the Type field of the 1st Exception object, if any\n\n\totherwise the Message field\n\n(2) the topmost entry from the Stacktrace field of the 1st Exception object, if any (3) the Value field of the 1st Exception object, if any, unwrapped as a single line (4) the Tags field (5) the Message field (7) the Type field (same as (1) for 1st exception) (8) the Value field (same as (3) for 1st exception) (9) the Stacktrace field (input to (2) on 1st exception) (10) the other fields on the Event object (11) the Extra field\n\n(Note how the top-level title fields (1) (3) are unrelated to the Message field in the event, which is surprising!)\n\nGiven this mapping, an error object is decomposed as follows:\n\n(1)/(7): \\\u003cfilename\u003e:\\\u003clineno\u003e (\\\u003cfunctionname\u003e) (3)/(8): \\\u003cerror type\u003e: \\\u003cfirst safe detail line, if any\u003e (4): not populated in this function, caller is to manage this (5): detailed structure of the entire error object, with references to \"additional data\"\n\n\tand additional \"exception\" objects\n\n(9): generated from innermost stack trace (6): every exception object after the 1st reports additional stack trace contexts (11): \"additional data\" populated from safe detail payloads\n\nIf there is no stack trace in the error, a synthetic Exception object is still produced to provide visual detail in the Sentry UI.\n\nNote that if a layer in the error has both a stack trace (ie provides the \\`StackTrace()\\` interface) and also safe details (\\`SafeDetails()\\`) other than the stack trace, only the stack trace is included in the Sentry report. This does not affect error types provided by the library, but could impact error types defined by 3rd parties. This limitation may be lifted in a later version.\n\n```go\nfunc Cause(err error) error\n```\nCause aliases UnwrapAll() for compatibility with github.com/pkg/errors.\n\n```go\nfunc CombineErrors(err, otherErr error) error\n```\nCombineErrors returns err, or, if err is nil, otherErr. if err is non-nil, otherErr is attached as secondary error. See the documentation of \\`WithSecondaryError()\\` for details.\n\n```go\nfunc DecodeError(ctx context.Context, enc EncodedError) error\n```\nDecodeError decodes an error.\n\n```go\nfunc EnsureNotInDomain(err error, constructor DomainOverrideFn, forbiddenDomains ...Domain) error\n```\nEnsureNotInDomain checks whether the error is in the given domain(s). If it is, the given constructor if provided is called to construct an alternate error. If no error constructor is provided, a new barrier is constructed automatically using the first provided domain as new domain. The original error message is preserved.\n\n```go\nfunc Errorf(format string, args ...interface{}) error\n```\nErrorf aliases Newf().\n\n```go\nfunc FlattenDetails(err error) string\n```\nFlattenDetails retrieves the details as per GetAllDetails() and concatenates them into a single string.\n\n```go\nfunc FlattenHints(err error) string\n```\nFlattenHints retrieves the hints as per GetAllHints() and concatenates them into a single string.\n\n```go\nfunc FormatError(err error, s fmt.State, verb rune)\n```\nFormatError formats an error according to s and verb. This is a helper meant for use when implementing the fmt.Formatter interface on custom error objects.\n\nIf the error implements errors.Formatter, FormatError calls its FormatError method of f with an errors.Printer configured according to s and verb, and writes the result to s.\n\nOtherwise, if it is a wrapper, FormatError prints out its error prefix, then recurses on its cause.\n\nOtherwise, its Error() text is printed.\n\n```go\nfunc Formattable(err error) fmt.Formatter\n```\nFormattable wraps an error into a fmt.Formatter which will provide \"smart\" formatting even if the outer layer of the error does not implement the Formatter interface.\n\n```go\nfunc GetAllDetails(err error) []string\n```\nGetAllDetails retrieves the details from the error using in post-order traversal.\n\n```go\nfunc GetAllHints(err error) []string\n```\nGetAllHints retrieves the hints from the error using in post-order traversal. The hints are de-duplicated. Assertion failures, issue links and unimplemented errors are detected and receive standard hints.\n\n```go\nfunc GetContextTags(err error) []*logtags.Buffer\n```\nGetContextTags retrieves the k/v pairs stored in the error. The sets are returned from outermost to innermost level of cause. The returned logtags.Buffer only know about the string representation of the values originally captured by the error.\n\n```go\nfunc GetOneLineSource(err error) (file string, line int, fn string, ok bool)\n```\nGetOneLineSource extracts the file/line/function information of the topmost caller in the innermost recorded stack trace. The filename is simplified to remove the path prefix.\n\nThis is used e.g. to populate the \"source\" field in PostgreSQL errors in CockroachDB.\n\n```go\nfunc GetTelemetryKeys(err error) []string\n```\nGetTelemetryKeys retrieves the (de-duplicated) set of all telemetry keys present in the direct causal chain of the error. The keys may not be sorted.\n\n```go\nfunc HandleAsAssertionFailure(origErr error) error\n```\nHandleAsAssertionFailure hides an error and turns it into an assertion failure. Both details from the original error and the context of the caller are preserved. The original error is not visible as cause any more. The original error message is preserved. See the doc of \\`AssertionFailedf()\\` for more details.\n\n```go\nfunc HandleAsAssertionFailureDepth(depth int, origErr error) error\n```\nHandleAsAssertionFailureDepth is like HandleAsAssertionFailure but the depth at which the call stack is captured can be specified.\n\n```go\nfunc Handled(err error) error\n```\nHandled swallows the provided error and hides it from the Cause()/Unwrap() interface, and thus the Is() facility that identifies causes. However, it retains it for the purpose of printing the error out (e.g. for troubleshooting). The error message is preserved in full.\n\nDetail is shown: - via \\`errors.GetSafeDetails()\\`, shows details from hidden error. - when formatting with \\`%+v\\`. - in Sentry reports.\n\n```go\nfunc HandledInDomain(err error, domain Domain) error\n```\nHandledInDomain creates an error in the given domain and retains the details of the given original error as context for debugging. The original error is hidden and does not become a \"cause\" for the new error. The original's error \\_message\\_ is preserved.\n\nSee the documentation of \\`WithDomain()\\` and \\`errors.Handled()\\` for details.\n\n```go\nfunc HandledInDomainWithMessage(err error, domain Domain, msg string) error\n```\nHandledInDomainWithMessage is like HandledWithMessage but with a domain.\n\n```go\nfunc HandledWithMessage(err error, msg string) error\n```\nHandledWithMessage is like Handled except the message is overridden. This can be used e.g. to hide message details or to prevent downstream code to make assertions on the message's contents.\n\n```go\nfunc HasAssertionFailure(err error) bool\n```\nHasAssertionFailure returns true if the error or any of its causes is an assertion failure annotation.\n\n```go\nfunc HasInterface(err error, referenceInterface interface{}) bool\n```\nHasInterface returns true if err contains an error which implements the interface pointed to by referenceInterface. The type of referenceInterface must be a pointer to an interface type. If referenceInterface is not a pointer to an interface, this function will panic.\n\n```go\nfunc HasIssueLink(err error) bool\n```\nHasIssueLink returns true iff the error or one of its causes has a linked issue payload.\n\n```go\nfunc HasType(err, referenceType error) bool\n```\nHasType returns true iff err contains an error whose concrete type matches that of referenceType.\n\n```go\nfunc HasUnimplementedError(err error) bool\n```\nHasUnimplementedError returns iff if err or its cause is an unimplemented error.\n\n```go\nfunc If(err error, pred func(err error) (interface{}, bool)) (interface{}, bool)\n```\nIf iterates on the error's causal chain and returns a predicate's return value the first time the predicate returns true.\n\nNote: if any of the error types has been migrated from a previous package location or a different type, ensure that RegisterTypeMigration() was called prior to If().\n\n```go\nfunc Is(err, reference error) bool\n```\nIs determines whether one of the causes of the given error or any of its causes is equivalent to some reference error.\n\nAs in the Go standard library, an error is considered to match a reference error if it is equal to that target or if it implements a method Is(error) bool such that Is(reference) returns true.\n\nNote: the inverse is not true - making an Is(reference) method return false does not imply that errors.Is() also returns false. Errors can be equal because their network equality marker is the same. To force errors to appear different to Is(), use errors.Mark().\n\nNote: if any of the error types has been migrated from a previous package location or a different type, ensure that RegisterTypeMigration() was called prior to Is().\n\n```go\nfunc IsAny(err error, references ...error) bool\n```\nIsAny is like Is except that multiple references are compared.\n\nNote: if any of the error types has been migrated from a previous package location or a different type, ensure that RegisterTypeMigration() was called prior to IsAny().\n\n```go\nfunc IsAssertionFailure(err error) bool\n```\nIsAssertionFailure returns true if the error (not its causes) is an assertion failure annotation. Consider using markers.If or HasAssertionFailure to test both the error and its causes.\n\n```go\nfunc IsIssueLink(err error) bool\n```\nIsIssueLink returns true iff the error (not its causes) has a linked issue payload.\n\n```go\nfunc IsUnimplementedError(err error) bool\n```\nIsUnimplementedError returns iff if err is an unimplemented error.\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 errs contains no non-nil values. 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. A stack trace is also retained.\n\n```go\nfunc JoinWithDepth(depth int, errs ...error) error\n```\nJoinWithDepth is like Join but the depth at which the call stack is captured can be specified.\n\n```go\nfunc Mark(err error, reference error) error\n```\nMark creates an explicit mark for the given error, using the same mark as some reference error.\n\nNote: if any of the error types has been migrated from a previous package location or a different type, ensure that RegisterTypeMigration() was called prior to Mark().\n\n```go\nfunc New(msg string) error\n```\nNew creates an error with a simple error message. A stack trace is retained.\n\nNote: the message string is assumed to not contain PII and is included in Sentry reports. Use errors.Newf(\"%s\", \\\u003cunsafestring\u003e) for errors strings that may contain PII information.\n\nDetail output: - message via \\`Error()\\` and formatting using \\`%v\\`/\\`%s\\`/\\`%q\\`. - everything when formatting with \\`%+v\\`. - stack trace and message via \\`errors.GetSafeDetails()\\`. - stack trace and message in Sentry reports.\n\n```go\nfunc NewAssertionErrorWithWrappedErrf(origErr error, format string, args ...interface{}) error\n```\nNewAssertionErrorWithWrappedErrf wraps an error and turns it into an assertion error. Both details from the original error and the context of the caller are preserved. The original error is not visible as cause any more. The original error message is preserved. See the doc of \\`AssertionFailedf()\\` for more details.\n\n```go\nfunc NewWithDepth(depth int, msg string) error\n```\nNewWithDepth is like New() except the depth to capture the stack trace is configurable. See the doc of \\`New()\\` for more details.\n\n```go\nfunc NewWithDepthf(depth int, format string, args ...interface{}) error\n```\nNewWithDepthf is like Newf() except the depth to capture the stack trace is configurable. See the doc of \\`New()\\` for more details.\n\n```go\nfunc Newf(format string, args ...interface{}) error\n```\nNewf creates an error with a formatted error message. A stack trace is retained.\n\nNote: the format string is assumed to not contain PII and is included in Sentry reports. Use errors.Newf(\"%s\", \\\u003cunsafestring\u003e) for errors strings that may contain PII information.\n\nSee the doc of \\`New()\\` for more details.\n\n```go\nfunc NotInDomain(err error, doms ...Domain) bool\n```\nNotInDomain returns true if and only if the error's domain is not one of the specified domains.\n\n```go\nfunc Opaque(err error) error\n```\nOpaque aliases barrier.Handled(), for compatibility with xerrors.\n\n```go\nfunc Redact(r interface{}) string\n```\nRedact returns a redacted version of the supplied item that is safe to use in anonymized reporting.\n\nNB: this interface is obsolete. Use redact.Sprint() directly.\n\n```go\nfunc RegisterLeafDecoder(typeName TypeKey, decoder LeafDecoder)\n```\nRegisterLeafDecoder can be used to register new leaf error types to the library. Registered types will be decoded using their own Go type when an error is decoded. Wrappers that have not been registered will be decoded using the opaqueLeaf type.\n\nNote: if the error type has been migrated from a previous location or a different type, ensure that RegisterTypeMigration() was called prior to RegisterLeafDecoder().\n\n```go\nfunc RegisterLeafEncoder(typeName TypeKey, encoder LeafEncoder)\n```\nRegisterLeafEncoder can be used to register new leaf error types to the library. Registered types will be encoded using their own Go type when an error is encoded. Wrappers that have not been registered will be encoded using the opaqueLeaf type.\n\nNote: if the error type has been migrated from a previous location or a different type, ensure that RegisterTypeMigration() was called prior to RegisterLeafEncoder().\n\n```go\nfunc RegisterMultiCauseDecoder(theType TypeKey, decoder MultiCauseDecoder)\n```\nRegisterMultiCauseDecoder can be used to register new multi-cause wrapper types to the library. Registered wrappers will be decoded using their own Go type when an error is decoded. Multi-cause wrappers that have not been registered will be decoded using the opaqueWrapper type.\n\n```go\nfunc RegisterMultiCauseEncoder(typeName TypeKey, encoder MultiCauseEncoder)\n```\nRegisterMultiCauseEncoder can be used to register new multi-cause error types to the library. Registered types will be encoded using their own Go type when an error is encoded. Multi-cause wrappers that have not been registered will be encoded using the opaqueWrapper type.\n\n```go\nfunc RegisterTypeMigration(previousPkgPath, previousTypeName string, newType error)\n```\nRegisterTypeMigration tells the library that the type of the error given as 3rd argument was previously known with type previousTypeName, located at previousPkgPath.\n\nThe value of previousTypeName must be the result of calling reflect.TypeOf(err).String() on the original error object. This is usually composed as follows:\n\n\t[*]\u003cshortpackage\u003e.\u003cerrortype\u003e\n\nFor example, Go's standard error type has name \"\\*errors.errorString\". The asterisk indicates that \\`errorString\\` implements the \\`error\\` interface via pointer receiver.\n\nMeanwhile, the singleton error type context.DeadlineExceeded has name \"context.deadlineExceededError\", without asterisk because the type implements \\`error\\` by value.\n\nRemember that the short package name inside the error type name and the last component of the package path can be different. This is why they must be specified separately.\n\n```go\nfunc RegisterWrapperDecoder(typeName TypeKey, decoder WrapperDecoder)\n```\nRegisterWrapperDecoder can be used to register new wrapper types to the library. Registered wrappers will be decoded using their own Go type when an error is decoded. Wrappers that have not been registered will be decoded using the opaqueWrapper type.\n\nNote: if the error type has been migrated from a previous location or a different type, ensure that RegisterTypeMigration() was called prior to RegisterWrapperDecoder().\n\n```go\nfunc RegisterWrapperEncoder(typeName TypeKey, encoder WrapperEncoder)\n```\nRegisterWrapperEncoder can be used to register new wrapper types to the library. Registered wrappers will be encoded using their own Go type when an error is encoded. Wrappers that have not been registered will be encoded using the opaqueWrapper type.\n\nNote: if the error type has been migrated from a previous location or a different type, ensure that RegisterTypeMigration() was called prior to RegisterWrapperEncoder().\n\n```go\nfunc RegisterWrapperEncoderWithMessageType(typeName TypeKey, encoder WrapperEncoderWithMessageType)\n```\nRegisterWrapperEncoderWithMessageType can be used to register new wrapper types to the library. These wrappers can optionally override the child error messages with their own error string instead of relying on iterative concatenation. Registered wrappers will be encoded using their own Go type when an error is encoded. Wrappers that have not been registered will be encoded using the opaqueWrapper type.\n\nNote: if the error type has been migrated from a previous location or a different type, ensure that RegisterTypeMigration() was called prior to RegisterWrapperEncoder().\n\n```go\nfunc ReportError(err error) string\n```\nReportError reports the given error to Sentry. The caller is responsible for checking whether telemetry is enabled, and calling the sentry.Flush() function to wait for the report to be uploaded. (By default, Sentry submits reports asynchronously.)\n\nNote: an empty 'eventID' can be returned which signifies that the error was not reported. This can occur when Sentry client hasn't been properly configured or Sentry client decided to not report the error (due to configured sampling rate, callbacks, Sentry's event processors, etc).\n\n```go\nfunc Safe(v interface{}) redact.SafeValue\n```\nSafe wraps the given object into an opaque struct that implements SafeMessager: its contents can be included as-is in PII-free strings in error objects and reports.\n\nNB: this is obsolete. Use redact.Safe instead.\n\n```go\nfunc SetWarningFn(fn func(context.Context, string, ...interface{}))\n```\nSetWarningFn enables configuration of the warning function.\n\n```go\nfunc UnimplementedError(issueLink IssueLink, msg string) error\n```\nUnimplementedError creates a new leaf error that indicates that some feature was not (yet) implemented.\n\nDetail is shown: - via \\`errors.GetSafeDetails()\\` - when formatting with \\`%+v\\`. - in Sentry reports. - via \\`errors.GetAllHints()\\` / \\`errors.FlattenHints()\\`\n\n```go\nfunc UnimplementedErrorf(issueLink IssueLink, format string, args ...interface{}) error\n```\nUnimplementedErrorf creates a new leaf error that indicates that some feature was not (yet) implemented. The message is formatted.\n\n```go\nfunc Unwrap(err error) error\n```\nUnwrap aliases UnwrapOnce() for compatibility with xerrors.\n\n```go\nfunc UnwrapAll(err error) error\n```\nUnwrapAll accesses the root cause object of the error. If the error has no cause (leaf error), it is returned directly.\n\n```go\nfunc UnwrapOnce(err error) error\n```\nUnwrapOnce accesses the direct cause of the error if any, otherwise returns nil.\n\nIt supports both errors implementing causer (\\`Cause()\\` method, from github.com/pkg/errors) and \\`Wrapper\\` (\\`Unwrap()\\` method, from the Go 2 error proposal).\n\n```go\nfunc WithAssertionFailure(err error) error\n```\nWithAssertionFailure decorates the error with an assertion failure marker. This is not intended to be used directly (see AssertionFailed() for further decoration).\n\nDetail is shown: - when formatting with \\`%+v\\`. - in Sentry reports.\n\n```go\nfunc WithContextTags(err error, ctx context.Context) error\n```\nWithContextTags captures the k/v pairs stored in the context via the \\`logtags\\` package and annotates them on the error.\n\nOnly the strong representation of values remains available. This is because the library cannot guarantee that the underlying value is preserved across the network. To avoid creating a stateful interface (where the user code needs to know whether an error has traveled through the network or not), the library restricts access to the value part as strings. See GetContextTags() below.\n\nDetail is shown: - via \\`errors.GetSafeDetails()\\`. - via \\`GetContextTags()\\` below. - when formatting with \\`%+v\\`. - in Sentry reports.\n\n```go\nfunc WithDetail(err error, msg string) error\n```\nWithDetail decorates an error with a textual detail. The detail may contain PII and thus will not reportable. The suggested use case for detail is to augment errors with information useful for debugging.\n\nDetail is shown: - when formatting with \\`%+v\\`. - with \\`GetAllDetails()\\` / \\`FlattenDetails()\\` below.\n\nNote: the detail does not appear in the main error message returned with Error(). Use GetAllDetails() or FlattenDetails() to retrieve it.\n\n```go\nfunc WithDetailf(err error, format string, args ...interface{}) error\n```\nWithDetailf is a helper that formats the detail string. See the documentation of WithDetail() for details.\n\n```go\nfunc WithDomain(err error, domain Domain) error\n```\nWithDomain wraps an error so that it appears to come from the given domain.\n\nDomain is shown: - via \\`errors.GetSafeDetails()\\`. - when formatting with \\`%+v\\`. - in Sentry reports.\n\n```go\nfunc WithHint(err error, msg string) error\n```\nWithHint decorates an error with a textual hint. The hint may contain PII and thus will not reportable. The suggested use case for hint is to relay information to end users.\n\nHint is shown: - when formatting with \\`%+v\\`. - with \\`GetAllHints()\\` / \\`FlattenHints()\\` below.\n\nNote: the hint does not appear in the main error message returned with Error(). Use GetAllHints() or FlattenHints() to retrieve it.\n\n```go\nfunc WithHintf(err error, format string, args ...interface{}) error\n```\nWithHintf is a helper that formats the hint. See the documentation of WithHint() for details.\n\n```go\nfunc WithIssueLink(err error, issue IssueLink) error\n```\nWithIssueLink adds an annotation to a know issue on a web issue tracker.\n\nThe url and detail strings may contain PII and will be considered reportable.\n\nDetail is shown: - via \\`errors.GetSafeDetails()\\` - when formatting with \\`%+v\\`. - in Sentry reports. - via \\`errors.GetAllHints()\\` / \\`errors.FlattenHints()\\`\n\n```go\nfunc WithMessage(err error, msg string) error\n```\nWithMessage annotates err with a new message. If err is nil, WithMessage returns nil. The message is considered safe for reporting and is included in Sentry reports.\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. The message is formatted as per redact.Sprintf, to separate safe and unsafe strings for Sentry reporting.\n\n```go\nfunc WithSafeDetails(err error, format string, args ...interface{}) error\n```\nWithSafeDetails annotates an error with the given reportable details. The format is made available as a PII-free string, alongside with a PII-free representation of every additional argument. Arguments can be reported as-is (without redaction) by wrapping them using the Safe() function.\n\nIf the format is empty and there are no arguments, the error argument is returned unchanged.\n\nDetail is shown: - via \\`errors.GetSafeDetails()\\` - when formatting with \\`%+v\\`. - in Sentry reports.\n\n```go\nfunc WithSecondaryError(err error, additionalErr error) error\n```\nWithSecondaryError enhances the error given as first argument with an annotation that carries the error given as second argument.  The second error does not participate in cause analysis (Is, etc) and is only revealed when printing out the error or collecting safe (PII-free) details for reporting.\n\nIf additionalErr is nil, the first error is returned as-is.\n\nTip: consider using CombineErrors() below in the general case.\n\nDetail is shown: - via \\`errors.GetSafeDetails()\\`, shows details from secondary error. - when formatting with \\`%+v\\`. - in Sentry reports.\n\n```go\nfunc WithStack(err error) error\n```\nWithStack annotates err with a stack trace at the point WithStack was called.\n\nDetail is shown: - via \\`errors.GetSafeDetails()\\` - when formatting with \\`%+v\\`. - in Sentry reports. - when innermost stack capture, with \\`errors.GetOneLineSource()\\`.\n\n```go\nfunc WithStackDepth(err error, depth int) error\n```\nWithStackDepth annotates err with a stack trace starting from the given call depth. The value zero identifies the caller of WithStackDepth itself. See the documentation of WithStack() for more details.\n\n```go\nfunc WithTelemetry(err error, keys ...string) error\n```\nWithTelemetry annotates err with the given telemetry key(s). The telemetry keys must be PII-free.\n\nDetail is shown: - via \\`errors.GetSafeDetails()\\`. - via \\`GetTelemetryKeys()\\` below. - when formatting with \\`%+v\\`. - in Sentry reports.\n\n```go\nfunc Wrap(err error, msg string) error\n```\nWrap wraps an error with a message prefix. A stack trace is retained.\n\nNote: the prefix string is assumed to not contain PII and is included in Sentry reports. Use errors.Wrapf(err, \"%s\", \\\u003cunsafestring\u003e) for errors strings that may contain PII information.\n\nDetail output: - original error message + prefix via \\`Error()\\` and formatting using \\`%v\\`/\\`%s\\`/\\`%q\\`. - everything when formatting with \\`%+v\\`. - stack trace and message via \\`errors.GetSafeDetails()\\`. - stack trace and message in Sentry reports.\n\n```go\nfunc WrapWithDepth(depth int, err error, msg string) error\n```\nWrapWithDepth is like Wrap except the depth to capture the stack trace is configurable. The the doc of \\`Wrap()\\` for more details.\n\n```go\nfunc WrapWithDepthf(depth int, err error, format string, args ...interface{}) error\n```\nWrapWithDepthf is like Wrapf except the depth to capture the stack trace is configurable. The the doc of \\`Wrapf()\\` for more details.\n\n```go\nfunc Wrapf(err error, format string, args ...interface{}) error\n```\nWrapf wraps an error with a formatted message prefix. A stack trace is also retained. If the format is empty, no prefix is added, but the extra arguments are still processed for reportable strings.\n\nNote: the format string is assumed to not contain PII and is included in Sentry reports. Use errors.Wrapf(err, \"%s\", \\\u003cunsafestring\u003e) for errors strings that may contain PII information.\n\nDetail output: - original error message + prefix via \\`Error()\\` and formatting using \\`%v\\`/\\`%s\\`/\\`%q\\`. - everything when formatting with \\`%+v\\`. - stack trace, format, and redacted details via \\`errors.GetSafeDetails()\\`. - stack trace, format, and redacted details in Sentry reports.\n\n## Types\n\n```go\ntype Domain = domains.Domain\n```\nDomain is the type of a domain annotation.\n\n```go\nconst NoDomain Domain = domains.NoDomain\n```\nNoDomain is the domain of errors that don't originate from a barrier.\n\n```go\nfunc GetDomain(err error) Domain\n```\nGetDomain extracts the domain of the given error, or NoDomain if the error's cause does not have a domain annotation.\n\n```go\nfunc NamedDomain(domainName string) Domain\n```\nNamedDomain returns an error domain identified by the given string.\n\n```go\nfunc PackageDomain() Domain\n```\nPackageDomain returns an error domain that represents the package of its caller.\n\n```go\nfunc PackageDomainAtDepth(depth int) Domain\n```\nPackageDomainAtDepth returns an error domain that describes the package at the given call depth.\n\n```go\ntype DomainOverrideFn = func(originalDomain Domain, err error) error\n```\nDomainOverrideFn is the type of the callback function passed to EnsureNotInDomain().\n\n```go\ntype EncodedError = errbase.EncodedError\n```\nEncodedError is the type of an encoded (and protobuf-encodable) error.\n\n```go\nfunc EncodeError(ctx context.Context, err error) EncodedError\n```\nEncodeError encodes an error.\n\n```go\ntype ErrorDetailer = hintdetail.ErrorDetailer\n```\nErrorDetailer is implemented by types that can provide user-informing detail strings.\n\n```go\ntype ErrorHinter = hintdetail.ErrorHinter\n```\nErrorHinter is implemented by types that can provide user-informing detail strings. This is implemented by withHint here, withIssueLink, assertionFailure and pgerror.Error.\n\n```go\ntype Formatter = errbase.Formatter\n```\nA Formatter formats error messages.\n\nNB: Consider implementing SafeFormatter instead. This will ensure that error displays can distinguish bits that are PII-safe.\n\n```go\ntype IssueLink = issuelink.IssueLink\n```\nIssueLink is the payload for a linked issue annotation.\n\n```go\nfunc GetAllIssueLinks(err error) (issues []IssueLink)\n```\nGetAllIssueLinks retrieves the linked issue carried by the error or its direct causes.\n\n```go\ntype LeafDecoder = errbase.LeafDecoder\n```\nLeafDecoder is to be provided (via RegisterLeafDecoder above) by additional wrapper types not yet known to this library. A nil return indicates that decoding was not successful.\n\n```go\ntype LeafEncoder = errbase.LeafEncoder\n```\nLeafEncoder is to be provided (via RegisterLeafEncoder above) by additional wrapper types not yet known to this library.\n\n```go\ntype MultiCauseDecoder = errbase.MultiCauseDecoder\n```\nMultiCauseDecoder is to be provided (via RegisterMultiCauseDecoder above) by additional multi-cause wrapper types not yet known by the library. A nil return indicates that decoding was not successful.\n\n```go\ntype MultiCauseEncoder = errbase.MultiCauseEncoder\n```\nMultiCauseEncoder is to be provided (via RegisterMultiCauseEncoder above) by additional multi-cause wrapper types not yet known to this library. The encoder will automatically extract and encode the causes of this error by calling \\`Unwrap()\\` and expecting a slice of errors.\n\n```go\ntype Printer = errbase.Printer\n```\nA Printer formats error messages.\n\nThe most common implementation of Printer is the one provided by package fmt during Printf (as of Go 1.13). Localization packages such as golang.org/x/text/message typically provide their own implementations.\n\n```go\ntype ReportableStackTrace = withstack.ReportableStackTrace\n```\nReportableStackTrace aliases the type of the same name in the sentry package. This is used by SendReport().\n\n```go\nfunc GetReportableStackTrace(err error) *ReportableStackTrace\n```\nGetReportableStackTrace extracts a stack trace embedded in the given error in the format suitable for Sentry reporting.\n\nThis supports:\n\n  - errors generated by github.com/pkg/errors (either generated locally or after transfer through the network),\n  - errors generated with WithStack() in this package,\n  - any other error that implements a StackTrace() method returning a StackTrace from github.com/pkg/errors.\n\nNote: Sentry wants the oldest call frame first, so the entries are reversed in the result.\n\n```go\ntype SafeDetailPayload = errbase.SafeDetailPayload\n```\nSafeDetailPayload captures the safe strings for one level of wrapping.\n\n```go\nfunc GetAllSafeDetails(err error) []SafeDetailPayload\n```\nGetAllSafeDetails collects the safe details from the given error object and all its causes. The details are collected from outermost to innermost level of cause.\n\n```go\nfunc GetSafeDetails(err error) (payload SafeDetailPayload)\n```\nGetSafeDetails collects the safe details from the given error object. If it is a wrapper, only the details from the wrapper are returned.\n\n```go\ntype SafeDetailer = errbase.SafeDetailer\n```\nSafeDetailer is an interface that can be implemented by errors that can provide PII-free additional strings suitable for reporting or telemetry.\n\n```go\ntype SafeFormatter = errbase.SafeFormatter\n```\nSafeFormatter is implemented by error leaf or wrapper types that want to separate safe and non-safe information when printed out.\n\nWhen multiple errors are chained (e.g. via errors.Wrap), intermediate layers in the error that do not implement SafeError are considered “unsafe”\n\n```go\ntype SafeMessager = redact.SafeMessager\n```\nSafeMessager aliases redact.SafeMessager.\n\nNB: this is obsolete. Use redact.SafeFormatter or errors.SafeFormatter instead.\n\n```go\ntype TypeKey = errbase.TypeKey\n```\nTypeKey identifies an error for the purpose of looking up decoders. It is equivalent to the \"family name\" in ErrorTypeMarker.\n\n```go\nfunc GetTypeKey(err error) TypeKey\n```\nGetTypeKey retrieve the type key for a given error object. This is meant for use in combination with the Register functions.\n\n```go\ntype Wrapper interface {\n\tUnwrap() error\n}\n```\nWrapper is the type of an error wrapper.\n\n```go\ntype WrapperDecoder = errbase.WrapperDecoder\n```\nWrapperDecoder is to be provided (via RegisterWrapperDecoder above) by additional wrapper types not yet known to this library. A nil return indicates that decoding was not successful.\n\n```go\ntype WrapperEncoder = errbase.WrapperEncoder\n```\nWrapperEncoder is to be provided (via RegisterWrapperEncoder above) by additional wrapper types not yet known to this library.\n\n```go\ntype WrapperEncoderWithMessageType = errbase.WrapperEncoderWithMessageType\n```\nWrapperEncoderWithMessageType is to be provided (via RegisterWrapperEncoderWithMessageType) by additional wrapper types not yet known to this library.\n\n","path":"github.com/cockroachdb/errors","name":"errors","synopsis":"","isRedistributable":true}
