-
Notifications
You must be signed in to change notification settings - Fork 65
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
Add Go 1.20 errors.Join support #106
Conversation
Signed-off-by: Steve Coffman <steve@khanacademy.org>
This is an example program which generates the example output above to play with how to format output when
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the initial pass. We'll want to extend this PR to properly support the detailed error formatting and the generation of sentry reports.
@knz any news on this? |
In progress. |
@StevenACoffman I incorporated your changes in separate branch PRs where I was compiling 1.20 compatibility work. Closing this PR since it's now merged. Thanks for the contribution. New releases will publish shortly with 1.20 support. |
(Edit knz) Informs #99 and cockroachdb/cockroach#97799
(Note: the work in this PR is important but not sufficient to handle the Go 1.20 changes - we need to extend the other components to properly support multierrors from other packages in network serialization/deserialization)
All errors using
cockroachdb/errors
that are combined using Go 1.20 std liberrors.Join
will lose the stacktrace when youfmt.Printf("%+v\n", err)
on the joined error. Also, without nativeerrors.Join
support, this library is not a drop in replacement for the Go 1.20 stdliberrors
package.This PR adds
errors.Join
from Go 1.20 stdlib, but with aFormat()
method so joined errors honor the format verbs. Joined errors are printed verbosely indexed in square brackets like[0]
, to differentiate them from the parenthetical indexing(0)
of wrapped errors.This PR is not meant to be merged as is, and is more for discussion (and is hopefully helpful rather than just annoying 😬 ).
It currently leans on Go 1.20 std lib pkg fmt's new
func FormatString(State, int32) string
fmt: add FormatString(State) string #51668, rather than using thecockroachdb/errors
internal format forwarding. As a result, this current implementation depends on Go 1.20+.It is likely that backwards compatibility with pre-Go 1.20 is desirable, so this
Format()
would need to be reworked to use this library'serrbase.Formatter
anderrbase.SafeFormatter
to avoid that.This change is