Closed matthchr closed 1 year ago
If there's agreement on the suggested solution above I'm happy to send a PR.
hey @matthchr - thanks for the detailed work here. your solution sounds good to me, yes please do send in a PR!
PR is here: https://github.com/onsi/gomega/pull/681
Repro code here:
Test_Repro4
panics with the following traceback:What actually happens for
Test_Repro4
is that for this code,actual
is aninterface{} | *CustomError
(a boxed nil).When this is passed through to func Object(object interface{}, indentation uint) string, it passes the
object.(error)
cast and soerr.Error()
is called, which panics.This doesn't happen for
Test_Repro2
(which calls an identical function toTest_Repro4
except the return type iserror
rather than a concrete type that implements error) becauseerror
is already an interface and so is not boxed.A possible solution for this problem would be to ensure that the
error
check guards against the possibility that the error is nil, like so: