Skip to content

m.Struct panics when called with non struct type #29

@kent-lfs

Description

@kent-lfs

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

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