Skip to content

Latest commit

 

History

History
executable file
·
24 lines (20 loc) · 721 Bytes

File metadata and controls

executable file
·
24 lines (20 loc) · 721 Bytes

ctxerr

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.

Usage

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
}