Documentation
¶
Overview ¶
Package kverrors provides structured errors
errors can be used with pkg/log to further enhance structured logging
Index ¶
- Constants
- func Add(err error, keyValuePairs ...interface{}) error
- func AddCtx(err error, ctx Context) error
- func KVSlice(err error) []interface{}
- func KVs(err error) map[string]interface{}
- func Message(err error) string
- func New(msg string, keysAndValues ...interface{}) error
- func NewCtx(msg string, ctx Context, keysAndValues ...interface{}) error
- func Root(err error) error
- func Unwrap(err error) error
- func Wrap(err error, msg string, keysAndValues ...interface{}) error
- type Context
- type KVError
Constants ¶
const ( MessageKey string = "msg" CauseKey string = "cause" )
Keys used to log specific builtin fields
Variables ¶
This section is empty.
Functions ¶
func Add ¶
Add adds key/value pairs to an error and returns the error WARNING: The original error is modified with this operation
func KVSlice ¶
func KVSlice(err error) []interface{}
KVSlice returns the key/value pairs associated with this error as a slice
Types ¶
type Context ¶
type Context []interface{}
Context is keyValuePairs wrapped to use later. Usage of this directly is not necessary See Context for more information
func NewContext ¶
func NewContext(keysAndValues ...interface{}) Context
NewContext creates key/value pairs to be used with errors later in the callstack. This provides the ability to create contextual information that will be used with any returned error
Example:
errCtx := kverrors.Context("cluster", clusterName, "namespace", namespace) ... if err != nil { return kverrors.Wrap(err, "failed to get namespace").Ctx(errCtx) } ... if err != nil { return kverrors.Wrap(err, "failed to update cluster").Ctx(errCtx) }
type KVError ¶
type KVError struct {
// contains filtered or unexported fields
}
KVError is an error that contains structured keys and values
func (*KVError) Error ¶
Error returns the string formatted error message. This is required to function as a standard library error
func (*KVError) MarshalJSON ¶
MarshalJSON implements json.Marshaler