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

fix(typeErr): workaround typeErr structFieldName overwritten #283

Closed
wants to merge 1 commit into from

Conversation

alexjx
Copy link

@alexjx alexjx commented Feb 21, 2022

If there is a nested struct go unmarshaled, the error message got overwritten. This create confusing error messages.

For example:

type ParamEntry struct {
	Required bool `json:"required,omitempty"`
}


type Spec struct {
	Params []ParamEntry `json:"params,omitempty"`
}

var content = `
params:
- required: yes
`

func TestGoyccYaml(t *testing.T)  {
	var s Spec
	err := yaml.UnmarshalWithOptions(
		[]byte(content),
		&s,
		yaml.UseOrderedMap(),
	)
	assert.NilError(t, err)
}

While unmarshal this, I go error message like this cannot unmarshal string into Go struct field Spec.Params of type bool, when Spec.Params is a slice of ParamEntry.

I try to concatenate the error, an alternative is to remove the "type" part of the underlying error. I'm submitting for discussion.

Jia

@goccy
Copy link
Owner

goccy commented May 1, 2022

Thank you for the contribution !
I think #280 makes ​​more understandable error .

@goccy goccy closed this Jun 6, 2022
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

Successfully merging this pull request may close these issues.

None yet

2 participants