-
Notifications
You must be signed in to change notification settings - Fork 8
Description
It's been about a year that this library has been in production use in multiple real-world revenue-generating products and I've got a good handle on the improvements I want to make and the direction this library is taking.
So, to mark this, I'd like to bundle the existing wrappers into a single package for a few reasons:
- remove the individual packages: fctx, fmsg, ftag and combine them into one
- introduce all the improvements listed in
- Support arbitrary value type in fctx metadata #38
- you'll be able to pass anything as a value, like stdlib slog.
- Play nicely with multierror libraries #9
- multi-error libraries will no longer cause confusion when unwrapping trees of errors
- Support Unwrap for multiple errors #25
- add support for the new Go standard
Unwrap() []errorinterface
- add support for the new Go standard
- Redesign fmsg to be less verbose and more useful. #32
- the "fmsg" (Fault message) library will only be concerned with end-user messages, not fmt.Errorf style internal messages
- Pass ...Wrapper list to New constructor #31
- No more
Wrap(New(...), wrappers...)justNew("msg", wrappers...)🥳
- No more
- Support arbitrary value type in fctx metadata #38
- settle on the API designs for v1 and commit to compatibility going forward
I'd like to use a single nice short package name for all the built-in wrappers, I'm thinking of just fault/f or fault/w. Mostly just for aesthetics, similar to how Zap and other log aggregators work:
Settled on wrap for context, tags and user-friendly error message reference wrappers
return fault.Wrap(err,
wrap.Ctx(ctx),
wrap.Tag(fault.TagNotFound),
wrap.Msg("There was a technical error while retrieving your account"),
)Previous ideas:
return fault.Wrap(err,
f.WithCtx(ctx), // decorate the error with key-value metadata from context
f.WithTag(ftag.NotFound), // categorise the error as a "not found"
f.WithMsg("There was a technical error while retrieving your account"), // provide an end-user message
)Or with:
return fault.Wrap(err,
with.Ctx(ctx), // decorate the error with key-value metadata from context
with.Tag(ftag.NotFound), // categorise the error as a "not found"
with.Msg("There was a technical error while retrieving your account"), // provide an end-user message
)Or just w
toqueteos pointed out this would be a bad idea as single letter symbols are often used for variable and parameter names.
return fault.Wrap(err,
w.Ctx(ctx), // decorate the error with key-value metadata from context
w.Tag(ftag.NotFound), // categorise the error as a "not found"
w.Msg("There was a technical error while retrieving your account"), // provide an end-user message
)Any ideas for this are welcome though! cc @matdurand @the-goodies @semihbkgr @toqueteos (just tagging folks who have contributed in case you have ideas or reservations around this!)