Skip to content
/ xerr Public

error handling utilities for golang

Notifications You must be signed in to change notification settings

rprtr258/xerr

Repository files navigation

xerr - error utilities library

Installation

go get github.com/rprtr258/xerr

Example usage

err := xerr.New(
    xerr.Message("user not found"),
    xerr.Errors{sql.NoRows},
    xerr.Fields{"trace_id": "abcabcabcabc"},
    xerr.Fields{
        "user_id": 1234,
        "user_page": "/posts",
    },
)

Trace id can be added as option from context in following way:

func WithTrace(ctx) xerr.Option {
    return xerr.Fields{"trace_id": getTraceIDFromCtx(ctx)}
}

Why

See post on motivation for this library.

Multiple libraries are around in go to help handling errors. But each one of them tackles only one task, e.g. adding caller metadata, adding stack metadata, formatting error messages, wrapping error, wrapping multiple errors, structured errors.

None of them is widely used to support all listed features and/or so is not supported actively. So I wrote all utils funcs I want to use while doing error handling making this lib.

THIS IS MY PERSONAL LIBRARY, EXPECT BREAKING CHANGES AND NO STABILITY. NOT READY AND WON'T BE READY FOR ANY USAGE BESIDES MY PERSONAL PROJECTS.

About

error handling utilities for golang

Resources

Stars

Watchers

Forks

Packages

No packages published