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

match.As not equivalent errors.As #19

Open
Fryuni opened this issue Jan 22, 2020 · 4 comments · May be fixed by #25
Open

match.As not equivalent errors.As #19

Fryuni opened this issue Jan 22, 2020 · 4 comments · May be fixed by #25

Comments

@Fryuni
Copy link

Fryuni commented Jan 22, 2020

package main

import (
	"fmt"

	"emperror.dev/errors"
	"emperror.dev/errors/match"
)

type (
	myErrorKind string
	MyError     struct {
		kind  myErrorKind
		cause error
	}
)

func (e MyError) Error() string {
	return fmt.Sprintf("%s: %+v", e.kind, e.cause)
}

func main() {
	var (
		err1 error = MyError{
			kind:  "my type",
			cause: errors.Sentinel("some error"),
		}
		targetTrueErrors MyError
		targetTrueMatch  MyError
	)

	fromErrorsTrue := errors.As(err1, &targetTrueErrors)
	fromMatchTrue := match.As(&targetTrueMatch).MatchError(err1)

	fmt.Println("Expecting true:")
	fmt.Printf("  From errors: %t\n", fromErrorsTrue)
	fmt.Printf("  From match : %t\n", fromMatchTrue)

	var (
		err2              error = errors.Sentinel("some error")
		targetFalseErrors MyError
		targetFalseMatch  MyError
	)

	fromErrorsFalse := errors.As(err2, &targetFalseErrors)
	fromMatchFalse := match.As(&targetFalseMatch).MatchError(err2)

	fmt.Println("Expecting false:")
	fmt.Printf("  From errors: %t\n", fromErrorsFalse)
	fmt.Printf("  From match : %t\n", fromMatchFalse)
}

// Output:
// Expecting true:
//  From errors: true
//  From match : true
// Expecting false:
//  From errors: false
//  From match : true

I suspect the problem is at this line, but since I'm in a hurry I haven't tried to solve the problem yet

@sagikazarmark
Copy link
Member

Thanks for opening this issue @Fryuni , sorry I missed it. Looking at it.

@AlekSi
Copy link

AlekSi commented Jul 29, 2020

Any news? :)

@sagikazarmark
Copy link
Member

Sorry, I didn't have time to look at it yet. PRs are always welcome though.

@Fryuni
Copy link
Author

Fryuni commented Jan 24, 2022

Took me a long while to get some time to contribute to OSS again. I'll send a PR fixing this in a moment

@Fryuni Fryuni linked a pull request Jan 24, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants