Skip to content

A tiny, handy package for contextual error types. Use it when you need to pass additional context to errors.

License

Notifications You must be signed in to change notification settings

KernelPryanic/ctxerr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
}

About

A tiny, handy package for contextual error types. Use it when you need to pass additional context to errors.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages