Skip to content

kinbiko/rogerr

rogerr

Build Status Coverage Status Go Report Card Latest version Go Documentation License

A Go package for error handling with structured metadata. Zero dependencies.

Blog post with detailed explanation.

Problem

Error messages that include unique data (user IDs, timestamps, etc.) break error grouping in monitoring tools like Sentry and Rollbar.

Solution

Store unique data as structured metadata separate from the error message. This package attaches metadata to Go's context.Context and preserves it when wrapping errors.

Usage

  1. Create an ErrorHandler: handler := rogerr.NewErrorHandler()
  2. Add metadata to context: ctx = rogerr.WithMetadatum(ctx, "userID", 123)
  3. Wrap errors with metadata: err = handler.Wrap(ctx, err, "operation failed")
  4. Extract metadata for logging: metadata := rogerr.Metadata(err)

Build Options

For cleaner stacktraces, use the -trimpath flag:

go build -trimpath ./cmd/myapp

This shows module-relative paths instead of absolute paths. Skip this if you disable stacktraces with rogerr.WithStacktrace(false).

Full documentation

Contributors

Generated from kinbiko/go-template