Skip to content

paramgen: 'index out of range' with invalid tag on embeded struct field #84

@hariso

Description

@hariso

Bug description

paramgen panics with index out of range if a field in an embedded struct has an invalid tag (for example, a validation tag).

Steps to reproduce

Save the following into a file in a directory called invalid3, and run go mod init example.com/invalid3:

package invalid3

type Config struct {
	AnotherConfig

	Param1 string
}

type AnotherConfig struct {
	AnotherParam string `json:"anotherParam" validate:"inclusion=foo,bar"`
}

Run the following tests:

// Fails with:
// panic: runtime error: index out of range [0] with length 0 [recovered]
func TestConfig(t *testing.T) {
	is := is.New(t)
	_, _, err := ParseParameters("./invalid3", "Config")
	is.NoErr(err)
}

// Fails with:
// err: [parseStructType] error parsing field "AnotherParam": [parseField] [parseIdent] invalid tag format
func TestAnotherConfig(t *testing.T) {
	is := is.New(t)
	_, _, err := ParseParameters("./invalid3", "AnotherConfig")
	is.NoErr(err)
}

Version

SDK version v0.7.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions