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

Clearer errors when decoding to invalid types #332

Merged
merged 1 commit into from
Nov 25, 2021
Merged

Clearer errors when decoding to invalid types #332

merged 1 commit into from
Nov 25, 2021

Conversation

arp242
Copy link
Collaborator

@arp242 arp242 commented Nov 25, 2021

When passing an invalid type such as "int" you would get the rather
unhelpful message of:

toml: cannot load TOML value of type map[string]interface {} into a Go integer

This adds an extra check for that, so that you get:

toml: cannot decode to type int

The second case is when you're using a wrong map type or struct field
type, the previous error message was:

toml: cannot load TOML value of type bool into a Go integer

So what exactly failed? No clue at all. This adds the TOML key:

toml: incompatible types: TOML key "F" has type bool; destination has type integer

Also clarify the errors for non-pointers and nil a wee bit while I'm
here.

Fixes #158

When passing an invalid type such as "int" you would get the rather
unhelpful message of:

	toml: cannot load TOML value of type map[string]interface {} into a Go integer

This adds an extra check for that, so that you get:

	toml: cannot decode to type int

The second case is when you're using a wrong map type or struct field
type, the previous error message was:

	toml: cannot load TOML value of type bool into a Go integer

So what exactly failed? No clue at all. This adds the TOML key:

	toml: incompatible types: TOML key "F" has type bool; destination has type integer

Also clarify the errors for non-pointers and nil a wee bit while I'm
here.

Fixes #158
@arp242 arp242 merged commit 4619257 into master Nov 25, 2021
@arp242 arp242 deleted the dec-err branch November 25, 2021 00:51
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.

Decoder: show field name and value with type errors
1 participant