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

WithTransform of nil error panics #420

Closed
cbandy opened this issue Feb 25, 2021 · 3 comments · Fixed by #423
Closed

WithTransform of nil error panics #420

cbandy opened this issue Feb 25, 2021 · 3 comments · Fixed by #423

Comments

@cbandy
Copy link
Contributor

cbandy commented Feb 25, 2021

The following panics in v1.10.5:

var err error
gomega.WithTransform(
	func(error) bool { return true },
	gomega.BeTrue(),
).Match(err)
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x56b58b]

goroutine 1 [running]:
github.com/onsi/gomega/matchers.(*WithTransformMatcher).Match(0xc00005e380, 0x0, 0x0, 0x7d5a18, 0xc00005e380, 0xc00006a058)
        /home/cbandy/go/pkg/mod/github.com/onsi/gomega@v1.10.5/matchers/with_transform.go:45 +0x6b
main.main()

I encountered it while using Eventually() to watch for a specific error, e.g.

Eventually(func () error { ... }).Should(WithTransform(os.IsNotExist, BeTrue()))
@ghost
Copy link

ghost commented Feb 25, 2021

Looks like WithTransform doesn't handle the actual being nil:

func (m *WithTransformMatcher) Match(actual interface{}) (bool, error) {
// return error if actual's type is incompatible with Transform function's argument type
actualType := reflect.TypeOf(actual)
if !actualType.AssignableTo(m.transformArgType) {

@onsi
Copy link
Owner

onsi commented Feb 25, 2021

sounds right - @jim-slattery-rs are you up for and have time to work on a PR to cover this case?

@ghost
Copy link

ghost commented Feb 25, 2021

Sure thing, I've created a PR: #422

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.

2 participants