A Go package for error handling with structured metadata. Zero dependencies.
Blog post with detailed explanation.
Error messages that include unique data (user IDs, timestamps, etc.) break error grouping in monitoring tools like Sentry and Rollbar.
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.
- Create an ErrorHandler:
handler := rogerr.NewErrorHandler() - Add metadata to context:
ctx = rogerr.WithMetadatum(ctx, "userID", 123) - Wrap errors with metadata:
err = handler.Wrap(ctx, err, "operation failed") - Extract metadata for logging:
metadata := rogerr.Metadata(err)
For cleaner stacktraces, use the -trimpath flag:
go build -trimpath ./cmd/myappThis shows module-relative paths instead of absolute paths.
Skip this if you disable stacktraces with rogerr.WithStacktrace(false).