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

Return a key with the error on Value.Populate failures #427

Merged
9 commits merged into from
Mar 22, 2017
Merged

Conversation

ghost
Copy link

@ghost ghost commented Mar 20, 2017

We provide only information about types, omitting the offending key, which can be confusing for users. The easiest way would be to return error from decoder.unmarshal, but because it is recursive, we need to track leafs and attach the offending key on leafs.

@ghost ghost requested a review from shawnburke March 20, 2017 21:25
@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 91.626% when pulling cf514df on alsam-configErrorPath into 81044df on alsam-configTypeAliases.

@ghost ghost force-pushed the alsam-configErrorPath branch from cf514df to 40fde52 Compare March 20, 2017 22:16
@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 91.626% when pulling 40fde52 on alsam-configErrorPath into 61b46f8 on alsam-configTypeAliases.

@ghost ghost changed the base branch from alsam-configTypeAliases to dev March 21, 2017 18:55
@coveralls
Copy link

Coverage Status

Coverage increased (+0.009%) to 91.866% when pulling ce8105a on alsam-configErrorPath into 70b504c on dev.

@@ -206,6 +207,10 @@ func addSeparator(key string) string {
return key
}

func addKeyToError(key string, err error) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: errorWithKey(err error, key string) is more meaningful.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, make sense

@@ -342,7 +347,8 @@ func (d *decoder) mapping(childKey string, value reflect.Value, def string) erro
for key := range v {
subKey := fmt.Sprintf("%v", key)
if subKey == "" {
return fmt.Errorf("empty key leads to ambiguity for path: %q", childKey)
// We can confuse an empty map key with a root element.
return addKeyToError(childKey, errors.New("empty map key is ambigious"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: is it worth adding another function, newErrorWithKey(msg string, key string), so we don't have to create error twice? A small performance win but not sure how much of a difference it makes. Will leave this to you.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather to keep an error here, so stacktrace is not going to get too long.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.07%) to 91.928% when pulling 77a2b49 on alsam-configErrorPath into 70b504c on dev.

@ghost ghost merged commit 08f900f into dev Mar 22, 2017
@ghost ghost deleted the alsam-configErrorPath branch March 22, 2017 01:22
glibsm pushed a commit that referenced this pull request Mar 28, 2017
We provide only information about types,
omitting the offending key, which can be
confusing for users. The easiest way would
be to return error from decoder.unmarshal,
but because it is recursive, we need to track
leafs and attach the offending key on leafs.
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants