Comments (3)
One of the main reasons I wanted to keep the wrappers separate was to emphasise that Fault itself is standalone and the real value it provides is the func (error) error
interface - on which you can build your own wrappers specific to your organisation or product. That's the fundamental sell of Fault as a library, then the wrappers like fctx/ftag are effectively reference implementations or examples of how to implement them as such.
I agree with the single letter point though, that's something I didn't consider!
Brevity has its pros and cons, too short and the meaning is lost, too long and it becomes arduous to use and read.
Perhaps wrap
is a logical package name for these:
return fault.Wrap(err,
wrap.Ctx(ctx),
wrap.Tag(fault.TagNotFound),
wrap.Msg("There was a technical error while retrieving your account"),
)
from fault.
Hi! Thanks for the ping
I'd advise against single letter imports as those are usually taken by variables (n
for counters, f
for *os.File
handles, w
for io.Writer
s, i
for loops, ...).
Why not just go all-in and get rid of the subpackage entirely? Just create some functional options that may or not be passed into fault.Wrap(err, ...)
.
Example:
return fault.Wrap(err,
fault.WithCtx(ctx), // decorate the error with key-value metadata from context
fault.WithTag(fault.TagNotFound), // categorise the error as a "not found"
fault.WithMsg("There was a technical error while retrieving your account"), // provide an end-user message
)
fault is almost there already, it's a matter of just moving some code up to the root.
This would only increase the API surface from 7 to 10+ symbols + the leftover types from those subpackages that are needed (like ftag.Kind
and the consts over there).
from fault.
Just my 2 cents, but if we're talking about 1.0 then I would consider the following. fmsg
and ftag
are packages used to store metadata about errors. There is obviously other types of metadata, for example, in my project, I basically copied ftag
to make an ErrorCode
concept that my http error handler is using to produce a response.
It seems to me that we could provide more generic version of ftag
and fmsg
, called for example fmeta
to enable to storage of any metadata types on top of errors. Then we could rewrite ftag
and even fmsg
using this generic fmeta
package. Obviously we would probably need to involve golang Generics at this point.
I feel it would provide far greater possibility for customizing fault for specific use cases.
If you think this is something worth pursuing, I could give it a try and come up with a first draft an a possible API and we could iterate on it.
from fault.
Related Issues (20)
- Make fault less opinionated on displaying "stack" trace and error messages together HOT 7
- Avoid dependencies HOT 2
- Refactor Flatten to first flatten the tree and then filter the results HOT 3
- Enable locations to be generated for the caller in libraries HOT 8
- Make fault.Wrap nil tolerant HOT 1
- Add fault for sql queries and parameters HOT 1
- More cleverly split up glued error messages
- Support Unwrap for multiple errors
- Underlying map is modified globally in fctx
- Not getting the expected output HOT 18
- Pass ...Wrapper list to New constructor
- Redesign fmsg to be less verbose and more useful. HOT 3
- Support multiple ftag HOT 5
- Support arbitrary value type in fctx metadata HOT 5
- De-duplication logic causes some sentinel error patterns to result in error chain losses
- Error chains are not aware of "non message" error wrappers HOT 1
- Message missing due to incomplete Format implementation
- Error prints do not include external errors in some cases HOT 1
- Play nicely with multierror libraries HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fault.