Skip to content

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

@Justinfan827

Description

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions