import (
"fmt"
"testing"
"github.com/davecgh/go-spew/spew"
"github.com/stretchr/testify/assert"
)
type NestedErr struct {
Err error
}
func (e *NestedErr) Error() string {
return e.Err.Error()
}
type ErrWrap struct {
NestedErr *NestedErr
}
func TestIfPanic(t *testing.T) {
its := assert.New(t)
err := ErrWrap{
NestedErr: &NestedErr{
Err: fmt.Errorf("this is an error"),
},
}
its.NotPanics(func() {
ss := spew.Sdump(err)
fmt.Println("LOGGING", ss)
})
}
go version go1.20.3 darwin/arm64
spew version: github.com/davecgh/go-spew v1.1.1
Note that this does not panic if I try to dump a pointer to ErrWrap e.g.
err := &ErrWrap{
NestedErr: &NestedErr{
Err: fmt.Errorf("this is an error"),
},
}