Skip to content
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

Go v1.20 Update for multi error #6

Closed
mvndaai opened this issue Nov 9, 2022 · 3 comments
Closed

Go v1.20 Update for multi error #6

mvndaai opened this issue Nov 9, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@mvndaai
Copy link
Owner

mvndaai commented Nov 9, 2022

Go added a errors.Join that allows joining errors. Together. This causes a problem with Unwrap because it can now return an array instead of just one error. This can lose fields that are joined together because doing unwrap will just unwrap the first one in the list.

golang/go#53435 (comment)

@mvndaai mvndaai added the enhancement New feature or request label Nov 9, 2022
@mvndaai
Copy link
Owner Author

mvndaai commented Sep 28, 2023

Needs something similar to what go error package does
https://cs.opensource.google/go/go/+/refs/tags/go1.21.1:src/errors/wrap.go;l=117-132

switch x := err.(type) {
case interface{ Unwrap() error }:
	err = x.Unwrap()
	if err == nil {
		return false
	}
case interface{ Unwrap() []error }:
	for _, err := range x.Unwrap() {
		if As(err, target) {
			return true
		}
	}
	return false
default:
	return false
}

@mvndaai
Copy link
Owner Author

mvndaai commented Sep 28, 2023

This should be a breadth first search so we still get the deepest fields.

@mvndaai
Copy link
Owner Author

mvndaai commented Sep 29, 2023

@mvndaai mvndaai closed this as completed Sep 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant