Expected behaviour
m.Struct should return error instead of panic when passed type is not of struct type. While it's expected that m.Struct will fail for non-struct type, it should not panic and instead return error.
Actual behaviour
m.Struct panics when passed type is not of struct type.
Use case
I put the m.Struct in generic stringify function within my logging package, and hoping to handle the error with fallback value if m.Struct call fails.
Reproduction code
import (
"testing"
masker "github.com/ggwhite/go-masker"
"github.com/stretchr/testify/require"
)
func TestRepro(t *testing.T) {
// obj := struct {
// Field1 int `json:"a"`
// }{Field1: 5}
obj := "string"
m := masker.New()
maskedObj, err := m.Struct(obj)
require.Error(t, err)
require.Nil(t, maskedObj)
}
Expected behaviour
m.Structshould return error instead of panic when passed type is not of struct type. While it's expected thatm.Structwill fail for non-struct type, it should not panic and instead return error.Actual behaviour
m.Structpanics when passed type is not of struct type.Use case
I put the
m.Structin generic stringify function within my logging package, and hoping to handle the error with fallback value ifm.Structcall fails.Reproduction code