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

spew.Dump panics when printing a custom error that wraps another custom error #144

Open
Justinfan827 opened this issue Jul 7, 2023 · 0 comments

Comments

@Justinfan827
Copy link

Justinfan827 commented Jul 7, 2023

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"),
		},
	}
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

No branches or pull requests

1 participant