This package provides functionality of propagation failure context information through errors. It's designed to enhance error logging with additional contextual information and pass it up the call stack. It's designed to be used with the log package in mind.
func funcA(ctx context.Context) {
...
logger := log.Default
if err := funcB(ctx); err != nil {
logger.Error().Ctx(ctxerr.Ctx(ctx, err)).Msg("An error occurred")
}
...
}
func funcB() error {
...
if err := funcC(ctx); err != nil {
return ctxerr.With(err, map[string]any{"operation": "someOperation", "details": "additional info"})
}
return nil
}