-
Notifications
You must be signed in to change notification settings - Fork 574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stack: remove github.com/pkg/errors
as a dependency
#470
Comments
Would you consider sending a PR? |
@rs Possibly, though likely couldn't be for a few weeks. If anyone else is interested in taking a crack at it, would be happy to see it! |
Signed-off-by: Bhargav Ravuri <[email protected]>
Signed-off-by: Bhargav Ravuri <[email protected]>
Signed-off-by: Bhargav Ravuri <[email protected]>
Signed-off-by: Bhargav Ravuri <[email protected]>
I have made new errors package https://gitlab.com/tozd/go/errors some time ago which addresses many issues filled through time at github.com/pkg/errors. I was planing to offer it as v2 of github.com/pkg/errors, but github.com/pkg/errors went into maintenance mode before that and I was unable to contact its maintainer through other means. So my package now lives its own (maintained) life, keeping the spirit of github.com/pkg/errors alive. It internally keeps dependency on github.com/pkg/errors (because sadly one needs to have access to the Stacktrace type to obtain stack traces in Go - one of the issues my package address by exposing stack trace using only standard types) but provides a maintained package to the outside world. Moreover, it keeps up to date with latest Go features like joining multiple errors into one error. And in general it made it clear that there is a difference between wrapping errors (like what stdlib does) and recording error's cause (like what github.com/pkg/errors did with its And this is where my main issue with zerolog's integration with github.com/pkg/errors is: it just extracts the stack trace, but there are at least two more other things to extract: which were original errors which caused the particular error a, and with new joins of multiple errors, what are those original errors, so one in fact gets a tree of potential other errors (and their messages and stack traces). My package supports JSON marshaling and you can see that there is more than just a stack trace to marshal. I have until now configured zerolog with support for my package for my own needs. But maybe there is a way that: a) replace github.com/pkg/errors with a dependency on my own package b) get JSON marshaling support also the tree of errors c) when pretty-printing errors with stack traces, also print out the stack trace. @rs: If you would be open to such a change I can make a PR to start in this direction. |
Hi, I have made an errors package which
using this |
As I mentioned here, I think zerolog should support only extracting raw
I could not find that. Moreover, the whole idea of me suggesting the use of gitlab.com/tozd/go/errors is so that zerolog could drop dependency on unmaintained github.com/pkg/errors (with gitlab.com/tozd/go/errors wrapping it and exposing it in a stable and maintained way). I think we all learned from the github.com/pkg/errors that returning a stack trace from an error with a custom type is a bad pattern so let's not repeat that. My overall proposal would be that error handling of errors in zerolog should:
And stack trace should then be converted to JSON from This is BTW all already supported through globals There are two issues which zerolog does not answer well currently though:
The last two issues his is why in my zerolog configuration I prefer having |
I would favor a solution that removes pkgerrors dep and does not add a new one. |
That would be a breaking change. Are you OK with that? In that case I suggest removing whole stack formatting and everything. I think |
I would probably be ok, but I’d like to get more feedback on such a breaking change. I can’t easily gauge how many people depend on this feature. |
Hi, I get now what you mean @mitar (I am quite experienced at misunderstanding ;)), also I agree with your view. It may be out of scope for this but personally I think it could make sense to differentiate two not exclusive types of stacktraces:
That being said at the moment I wouldn't know how to implement point 2. in other than these three ways:
So this comment may be a bit unconclusive if not as food for thought. |
Nice summary. I agree with your two types. In gitlab.com/tozd/go/errors 2. type is implemented through causer interface (
My proposal does address it: I think all those errors should handle JSON marshaling themselves and zerolog should not care about that. Zerolog might have some fallback for standard errors which do not implement JSON marshaling, but it could just be calling The only tricky question here is then how to pretty-print those JSON marshaled errors, to example show stack trace nicely but that requires just some heuristic in parsing out error's JSON, ideally having standard fields but there are also not so many combinations in there. In any case, zerolog does not really require a dependency on a 3rd party library for that either. And if you are using error package which does not support JSON marshal, you can do that yourself inside |
The
.Stack()
context method depends on pkg/errors which is now in Maintenance mode.Recommend removing this dependency, and bringing the stack functionality directly into this project.
The text was updated successfully, but these errors were encountered: