{"modulePath":"github.com/cockroachdb/errors","version":"v1.14.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package errbase\n\n## Functions\n\n```go\nfunc DecodeError(ctx context.Context, enc EncodedError) error\n```\nDecodeError decodes an error.\n\nCan only be called if the EncodedError is set (see IsSet()).\n\n```go\nfunc EqualTypeMark(e1, e2 error) bool\n```\nEqualTypeMark checks whether \\`GetTypeMark(e1).Equals(GetTypeMark(e2))\\`. It is written to be be optimized for the case where neither error has serialized type information.\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 FormatRedactableError(err error, s redact.SafePrinter, verb rune)\n```\nFormatRedactableError formats an error as a safe object.\n\nNote that certain verb/flags combinations are currently not supported, and result in a rendering that considers the entire object as unsafe. For example, %q, %#v are not yet supported.\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 GetTypeMark(err error) errorspb.ErrorTypeMark\n```\nGetTypeMark retrieves the ErrorTypeMark for a given error object. This is meant for use in the markers sub-package.\n\n```go\nfunc RegisterLeafDecoder(theType 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(theType 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(theType 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 RegisterSpecialCasePrinter(fn safeErrorPrinterFn)\n```\nRegisterSpecialCasePrinter registers a handler.\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(theType 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(theType 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(theType TypeKey, encoder WrapperEncoderWithMessageType)\n```\nRegisterWrapperEncoderWithMessageType 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\nThis function differs from RegisterWrapperEncoder by allowing the caller to explicitly decide whether the wrapper owns the entire error message or not. Otherwise, the relationship is inferred.\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 SetWarningFn(fn func(context.Context, string, ...interface{}))\n```\nSetWarningFn enables configuration of the warning function.\n\n```go\nfunc TestingWithEmptyMigrationRegistry() (restore func())\n```\nTestingWithEmptyMigrationRegistry is intended for use by tests.\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. UnwrapAll treats multi-errors as leaf nodes.\n\n```go\nfunc UnwrapMulti(err error) []error\n```\nUnwrapMulti access the slice of causes that an error contains, if it is a multi-error.\n\n```go\nfunc UnwrapOnce(err error) (cause 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\nUnwrapOnce treats multi-errors (those implementing the \\`Unwrap() \\[]error\\` interface as leaf-nodes since they cannot reasonably be iterated through to a single cause. These errors are typically constructed as a result of \\`fmt.Errorf\\` which results in a \\`wrapErrors\\` instance that contains an interpolated error string along with a list of causes.\n\nThe go stdlib does not define output on \\`Unwrap()\\` for a multi-cause error, so we default to nil here.\n\n## Types\n\n```go\ntype EncodedError = errorspb.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 Formatter interface {\n\terror\n\n\t// FormatError prints the receiver's first error.\n\t// The return value decides what happens in the case\n\t// FormatError() is used to produce a \"short\" message,\n\t// eg. when it is used to implement Error():\n\t//\n\t// - if it returns nil, then the short message\n\t//   contains no more than that produced for this error,\n\t//   even if the error has a further causal chain.\n\t//\n\t// - if it returns non-nil, then the short message\n\t//   contains the value printed by this error,\n\t//   followed by that of its causal chain.\n\t//   (e.g. thiserror: itscause: furthercause)\n\t//\n\t// Note that all the causal chain is reported in verbose reports in\n\t// any case.\n\tFormatError(p Printer) (next error)\n}\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 LeafDecoder = func(ctx context.Context, msg string, safeDetails []string, payload proto.Message) error\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 = func(ctx context.Context, err error) (msg string, safeDetails []string, payload proto.Message)\n```\nLeafEncoder is to be provided (via RegisterLeafEncoder above) by additional wrapper types not yet known to this library.\n\n```go\ntype MessageType errorspb.MessageType\n```\nMessageType is used to encode information about an error message within a wrapper error type. This information is used to affect display logic.\n\n```go\nconst (\n\t// Prefix denotes an error message that should be prepended to the\n\t// message of its cause.\n\tPrefix MessageType = MessageType(errorspb.MessageType_PREFIX)\n\t// FullMessage denotes an error message that contains the text of its\n\t// causes and can be displayed standalone.\n\tFullMessage = MessageType(errorspb.MessageType_FULL_MESSAGE)\n)\n```\nValues below should match the ones in errorspb.MessageType for direct conversion.\n\n```go\ntype MultiCauseDecoder = func(ctx context.Context, causes []error, msgPrefix string, safeDetails []string, payload proto.Message) error\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 = func(ctx context.Context, err error) (msg string, safeDetails []string, payload proto.Message)\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 OpaqueErrno struct {\n\t// contains filtered or unexported fields\n}\n```\nOpaqueErrno represents a syscall.Errno error object that was constructed on a different OS/platform combination.\n\n```go\nfunc (o *OpaqueErrno) Error() string\n```\nError implements the error interface.\n\n```go\nfunc (o *OpaqueErrno) Is(target error) bool\n```\nIs tests whether this opaque errno object represents a special os error type.\n\n```go\nfunc (o *OpaqueErrno) Temporary() bool\n```\nTemporary tests whether this opaque errno object encodes a temporary error.\n\n```go\nfunc (o *OpaqueErrno) Timeout() bool\n```\nTimeout tests whether this opaque errno object encodes a timeout error.\n\n```go\ntype Printer interface {\n\t// Print appends args to the message output.\n\tPrint(args ...interface{})\n\n\t// Printf writes a formatted string.\n\tPrintf(format string, args ...interface{})\n\n\t// Detail reports whether error detail is requested.\n\t// After the first call to Detail, all text written to the Printer\n\t// is formatted as additional detail, or ignored when\n\t// detail has not been requested.\n\t// If Detail returns false, the caller can avoid printing the detail at all.\n\tDetail() bool\n}\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 SafeDetailPayload struct {\n\t// OriginalTypeName is the concrete type of the error that the details\n\t// are coming from.\n\tOriginalTypeName string\n\t// ErrorTypeMark is the mark of the error that the details are\n\t// coming from. This may contain a different type name than\n\t// OriginalTypeName in case an error type was migrated.\n\tErrorTypeMark errorspb.ErrorTypeMark\n\t// SafeDetails are the PII-free strings.\n\tSafeDetails []string\n}\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\nfunc (s *SafeDetailPayload) Fill(slice []string) []string\n```\nFill can be used to concatenate multiple SafeDetailPayloads.\n\n```go\ntype SafeDetailer interface {\n\tSafeDetails() []string\n}\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 interface {\n\t// SafeFormatError prints the receiver's first error.\n\t//\n\t// The provided Printer behaves like a redact.SafePrinter its\n\t// Print() and Printf() methods conditionally add redaction markers\n\t// around unsafe bits.\n\t//\n\t// The return value of SafeFormatError() decides what happens in the\n\t// case the method is used to produce a \"short\" message, eg. when it\n\t// is used to implement Error():\n\t//\n\t// - if it returns nil, then the short message\n\t//   contains no more than that produced for this error,\n\t//   even if the error has a further causal chain.\n\t//\n\t// - if it returns non-nil, then the short message\n\t//   contains the value printed by this error,\n\t//   followed by that of its causal chain.\n\t//   (e.g. thiserror: itscause: furthercause)\n\t//\n\t// Note that all the causal chain is reported in verbose reports in\n\t// any case.\n\tSafeFormatError(p Printer) (next error)\n}\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 StackFrame = pkgErr.Frame\n```\nStackFrame is the type of a single call frame entry. This mirrors the type of the same name in github.com/pkg/errors.\n\n```go\ntype StackTrace = pkgErr.StackTrace\n```\nStackTrace is the type of the data for a call stack. This mirrors the type of the same name in github.com/pkg/errors.\n\n```go\nfunc ElideSharedStackTraceSuffix(prevStack, newStack StackTrace) (StackTrace, bool)\n```\nElideSharedStackTraceSuffix removes the suffix of newStack that's already present in prevStack. The function returns true if some entries were elided.\n\n```go\ntype StackTraceProvider interface {\n\tStackTrace() StackTrace\n}\n```\nStackTraceProvider is a provider of StackTraces. This is, intendedly, defined to be implemented by pkg/errors.stack.\n\n```go\ntype TypeKey string\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 TypeKeyMarker interface {\n\tErrorKeyMarker() string\n}\n```\nTypeKeyMarker can be implemented by errors that wish to extend their type name as seen by GetTypeKey().\n\nNote: the key marker is considered safe for reporting and is included in sentry reports.\n\n```go\ntype WrapperDecoder = func(ctx context.Context, cause error, msgPrefix string, safeDetails []string, payload proto.Message) error\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 func(ctx context.Context, err error) (\n\tmsgPrefix string,\n\tsafeDetails []string,\n\tpayload proto.Message,\n)\n```\nWrapperEncoder is to be provided (via RegisterWrapperEncoder above) by additional wrapper types not yet known to this library.\n\n```go\ntype WrapperEncoderWithMessageType func(ctx context.Context, err error) (\n\tmsgPrefix string,\n\tsafeDetails []string,\n\tpayload proto.Message,\n\tmessageType MessageType,\n)\n```\nWrapperEncoderWithMessageType is to be provided (via RegisterWrapperEncoderWithMessageType above) by additional wrapper types not yet known to this library. This encoder returns an additional enum which indicates whether the wrapper owns the error message completely instead of simply being a prefix with the error message of its causes appended to it. This information is encoded along with the prefix in order to provide context during error display.\n\n","path":"github.com/cockroachdb/errors/errbase","name":"errbase","synopsis":"","isRedistributable":true}
