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

Unmarshal panic when structure field type is custom #186

Closed
Aukstkalnis opened this issue Sep 12, 2017 · 1 comment
Closed

Unmarshal panic when structure field type is custom #186

Aukstkalnis opened this issue Sep 12, 2017 · 1 comment
Labels
bug Issues describing a bug in go-toml.

Comments

@Aukstkalnis
Copy link

I created toml file:

[[Device]]
Imei = 3500000000000
Job = 0

[[Device]]
Imei = 3500000000000
Job = 0

Code:
type Job uint8
type Device struct {
Imei uint64
AssignedJob Job
}
...
type DeviceList []Device
var dev DeviceList
toml.Unmarchal(file, &dev)

An I get panic:
panic: reflect.Set: value of type uint8 is not assignable to type device.Job [recovered]
panic: reflect.Set: value of type uint8 is not assignable to type device.Job

goroutine 18 [running]:
testing.tRunner.func1(0xc0420ac0f0)
C:/go/src/testing/testing.go:711 +0x2d9
panic(0x559e20, 0xc0420e95b0)
C:/go/src/runtime/panic.go:491 +0x291
reflect.Value.assignTo(0x559fa0, 0x648ca0, 0x88, 0x590d16, 0xb, 0x558a20, 0x0, 0x559720, 0x679fa0, 0x0)
C:/go/src/reflect/value.go:2186 +0x3ad
reflect.Value.Set(0x558a20, 0xc042052af8, 0x188, 0x559fa0, 0x648ca0, 0x88)
C:/go/src/reflect/value.go:1351 +0xab
github.com/pelletier/go-toml.valueFromTree(0x649760, 0x57a540, 0xc042051840, 0xa, 0x556b20, 0xc0420f8780, 0x97, 0x649760)
D:/Projects/Go_Projects/src/github.com/pelletier/go-toml/marshal.go:283 +0x45f
github.com/pelletier/go-toml.valueFromTreeSlice(0x649760, 0x556b20, 0xc04209e780, 0xa, 0x10, 0x411e63, 0xc0420b2ea0, 0x646a80, 0xc0420b2f78, 0xc0)
D:/Projects/Go_Projects/src/github.com/pelletier/go-toml/marshal.go:306 +0x171
github.com/pelletier/go-toml.valueFromToml(0x649760, 0x556b20, 0x556560, 0xc0420f8600, 0xc0420f8600, 0x556b20, 0x0, 0x0, 0x0)
D:/Projects/Go_Projects/src/github.com/pelletier/go-toml/marshal.go:337 +0x1a7
github.com/pelletier/go-toml.valueFromTree(0x649760, 0x5695e0, 0xc042051820, 0x100, 0xc042051820, 0xb5, 0x100, 0xc04203bbd0)
D:/Projects/Go_Projects/src/github.com/pelletier/go-toml/marshal.go:279 +0x3a4
github.com/pelletier/go-toml.(*Tree).Unmarshal(0xc042051820, 0x54fb20, 0xc042051800, 0x0, 0x0)
D:/Projects/Go_Projects/src/github.com/pelletier/go-toml/marshal.go:235 +0x173
github.com/pelletier/go-toml.Unmarshal(0xc0420be000, 0x4bb, 0x6bb, 0x54fb20, 0xc042051800, 0x0, 0x0)

When I use json, there is no panic, so I think there should also to be no panic.

@pelletier
Copy link
Owner

Thank you for the bug report! You are right: Unmarshal should not panic, and only return an error in that case.

@pelletier pelletier added the bug Issues describing a bug in go-toml. label Oct 1, 2017
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.
Projects
None yet
Development

No branches or pull requests

2 participants