Add Go 1.20 errors.Join support #106
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
(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