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.
funcfuncA(ctx context.Context) {
...logger:=log.Defaultiferr:=funcB(ctx); err!=nil {
logger.Error().Ctx(ctxerr.Ctx(ctx, err)).Msg("An error occurred")
}
...
}
funcfuncB() error {
...iferr:=funcC(ctx); err!=nil {
returnctxerr.With(err, map[string]any{"operation": "someOperation", "details": "additional info"})
}
returnnil
}