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

beta7: Encode: panic: reflect: NumField of non-struct type #752

Closed
bep opened this issue Apr 8, 2022 · 2 comments · Fixed by #753
Closed

beta7: Encode: panic: reflect: NumField of non-struct type #752

bep opened this issue Apr 8, 2022 · 2 comments · Fixed by #753
Labels
bug Issues describing a bug in go-toml. v2 Issues impacting the v2 major version.

Comments

@bep
Copy link

bep commented Apr 8, 2022

Got some tests errors in Hugo. Note that the failures comes from some usage of Encode in some old test code that in itself looks suspicious and needs fixing. But I suspect that the error situation is a real one and needs a well defined behaviour.

Note that config.Provider is an interface (https://godocs.io/github.com/gohugoio/hugo/config#Provider) implemented by a plain struct.

  panic: reflect: NumField of non-struct type config.Provider [recovered]
	panic: reflect: NumField of non-struct type config.Provider

goroutine 50 [running]:
testing.tRunner.func1.2({0x10596b640, 0x1400028e8f0})
	/usr/local/go/src/testing/testing.go:1389 +0x1c8
testing.tRunner.func1()
	/usr/local/go/src/testing/testing.go:1392 +0x384
panic({0x10596b640, 0x1400028e8f0})
	/usr/local/go/src/runtime/panic.go:838 +0x204
reflect.(*rtype).NumField(0x105a8c620?)
	/usr/local/go/src/reflect/type.go:1026 +0x70
github.com/pelletier/go-toml/v2.walkStruct({{0x1400028e8c0, 0x1, 0x1}, {0x0, 0x0}, 0x0, 0x0, 0x1, 0x0, 0x0, ...}, ...)
	/Users/bep/go/pkg/mod/github.com/pelletier/go-toml/v2@v2.0.0-beta.7/marshaler.go:579 +0xa0
github.com/pelletier/go-toml/v2.walkStruct({{0x1400028e8c0, 0x1, 0x1}, {0x0, 0x0}, 0x0, 0x0, 0x1, 0x0, 0x0, ...}, ...)
	/Users/bep/go/pkg/mod/github.com/pelletier/go-toml/v2@v2.0.0-beta.7/marshaler.go:603 +0x21c
github.com/pelletier/go-toml/v2.(*Encoder).encodeStruct(0x14000253290?, {0x14000745800, 0x6d3, 0x800}, {{0x1400028e8c0, 0x1, 0x1}, {0x0, 0x0}, 0x0, ...}, ...)
	/Users/bep/go/pkg/mod/github.com/pelletier/go-toml/v2@v2.0.0-beta.7/marshaler.go:631 +0xa8
github.com/pelletier/go-toml/v2.(*Encoder).encode(0x14000768f88?, {0x14000745800, 0x6d3, 0x800}, {{0x1400028e8c0, 0x1, 0x1}, {0x0, 0x0}, 0x0, ...}, ...)
	/Users/bep/go/pkg/mod/github.com/pelletier/go-toml/v2@v2.0.0-beta.7/marshaler.go:243 +0x814
github.com/pelletier/go-toml/v2.(*Encoder).encode(0x105af8780?, {0x14000745800, 0x6d3, 0x800}, {{0x1400028e8c0, 0x1, 0x1}, {0x0, 0x0}, 0x0, ...}, ...)
	/Users/bep/go/pkg/mod/github.com/pelletier/go-toml/v2@v2.0.0-beta.7/marshaler.go:257 +0x6a0
github.com/pelletier/go-toml/v2.(*Encoder).encodeSliceAsArrayTable(0x1058d0000?, {0x14000745800, 0x6bf, 0x800}, {{0x1400028e8c0, 0x1, 0x1}, {0x0, 0x0}, 0x0, ...}, ...)
	/Users/bep/go/pkg/mod/github.com/pelletier/go-toml/v2@v2.0.0-beta.7/marshaler.go:870 +0x2f0
github.com/pelletier/go-toml/v2.(*Encoder).encodeSlice(0x140004f7fe0?, {0x14000745800, 0x6bf, 0x800}, {{0x0, 0x0, 0x0}, {0x1400053be20, 0xf}, 0x1, ...}, ...)
	/Users/bep/go/pkg/mod/github.com/pelletier/go-toml/v2@v2.0.0-beta.7/marshaler.go:838 +0x150

In beta6, this is what:

[[languagessorted]]
Lang = 'en'
LanguageName = ''
LanguageDirection = ''
Title = ''
Weight = 0
Disabled = false
ContentDir = ''
[languagessorted.Cfg]
[languagessorted.LocalCfg]
[languagessorted.Provider]
@pelletier pelletier added bug Issues describing a bug in go-toml. v2 Issues impacting the v2 major version. labels Apr 8, 2022
pelletier added a commit that referenced this issue Apr 8, 2022
Resolve marshaling regression when handling an embedded interface in a
struct.

Fixes #752
pelletier added a commit that referenced this issue Apr 8, 2022
Resolve marshaling regression when handling an embedded interface in a
struct.

Fixes #752
@pelletier
Copy link
Owner

Thanks a lot for trying it out! I think this patch should fix the regression: 2377ac4 (incorrectly trying to walk an embedded interface as if it was a struct).

@pelletier pelletier linked a pull request Apr 8, 2022 that will close this issue
@bep
Copy link
Author

bep commented Apr 11, 2022

Yes, the tests passes with 2377ac4

@bep bep closed this as completed Apr 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues describing a bug in go-toml. v2 Issues impacting the v2 major version.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants