{"modulePath":"github.com/interspace/errors","version":"v1.2.4","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\n```go\nfunc FormatError(err error, s fmt.State, verb rune)\n```\nFormatError formats an error according to s and verb.\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 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 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 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.\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\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 and returns the next error in\n\t// the error chain, if any.\n\tFormatError(p Printer) (next error)\n}\n```\nA Formatter formats error messages.\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 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 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\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) (msgPrefix string, safeDetails []string, payload proto.Message)\n```\nWrapperEncoder is to be provided (via RegisterWrapperEncoder above) by additional wrapper types not yet known to this library.\n\n","path":"github.com/interspace/errors/errbase","name":"errbase","synopsis":"","isRedistributable":true}
