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

errors unmarshalling inline structs are swallowed in Strict mode #243

Closed
quentinmit opened this issue Aug 9, 2021 · 2 comments
Closed

Comments

@quentinmit
Copy link
Contributor

While trying to implement a custom marshaler/unmarshaler for durations: https://play.golang.org/p/TQnD5pV-381

I discovered that any errors that occur when unmarshaling inline structs get swallowed. I think this is happening because of this block of code in decode.go:

https://github.com/goccy/go-yaml/blob/v1.9.2/decode.go#L984

			newFieldValue, err := d.createDecodedNewValue(ctx, fieldValue.Type(), mapNode)
			if d.disallowUnknownField {
				var ufe *unknownFieldError
				if xerrors.As(err, &ufe) {
					err = nil
				}

				if err = d.deleteStructKeys(fieldValue.Type(), unknownFields); err != nil {
					return errors.Wrapf(err, "cannot delete struct keys")
				}
			}

			if err != nil {
				if foundErr != nil {
					continue
				}

The call to deleteStructKeys overwrites the err variable from createDecodedNewValue before it has been checked. Perhaps this is as simple as adding a missing colon.

quentinmit added a commit to quentinmit/go-yaml that referenced this issue Aug 10, 2021
@quentinmit
Copy link
Contributor Author

That was indeed the fix, so I sent a PR.

goccy added a commit that referenced this issue Aug 10, 2021
Fix error reporting on inline structs in strict mode (#243)
@quentinmit
Copy link
Contributor Author

I believe this is now fixed with those two PRs.

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

No branches or pull requests

1 participant