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

Encode and decode time.Duration fields (#201) #246

Merged
merged 4 commits into from
Aug 25, 2021

Conversation

quentinmit
Copy link
Contributor

This uses time.ParseDuration and time.Duration.String, and is
compatible with gopkg.in/yaml's encoding.

This uses `time.ParseDuration` and `time.Duration.String`, and is
compatible with gopkg.in/yaml's encoding.
@codecov-commenter
Copy link

codecov-commenter commented Aug 11, 2021

Codecov Report

Merging #246 (0206999) into master (e2008a9) will increase coverage by 0.25%.
The diff coverage is 87.87%.

@@            Coverage Diff             @@
##           master     #246      +/-   ##
==========================================
+ Coverage   78.47%   78.73%   +0.25%     
==========================================
  Files          12       12              
  Lines        3419     3451      +32     
==========================================
+ Hits         2683     2717      +34     
+ Misses        502      501       -1     
+ Partials      234      233       -1     

Copy link
Owner

@goccy goccy left a comment

Choose a reason for hiding this comment

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

Thank you for the great PR ! I commented on some points .

decode.go Outdated
func (d *Decoder) decodeDuration(ctx context.Context, dst reflect.Value, src ast.Node) error {
t, err := d.castToDuration(src)
if err != nil {
return err
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
return err
return errors.Wrapf(err, "failed to convert to duration")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is already wrapped (if necessary) inside castToDuration

Copy link
Owner

Choose a reason for hiding this comment

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

Yes! That's right. However, we still need to wrap the err in order to get the stack trace printed correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, are you saying I should wrap it twice? I'm currently matching the existing implementation of decodeTime, which also doesn't wrap the error a second time.

Copy link
Owner

Choose a reason for hiding this comment

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

Yes, it's need to improve debuggability ( please try to output error with %+v )
Oh, decodeTime's case is wrong. It's need to wrap...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the call to Wrapf on both decodeDuration and decodeTime. I also added a test case so you can see the resulting messages. It looks like in most cases the stack trace is getting lost anyway at line 1059 when the error is unwrapped before being returned.

encode.go Show resolved Hide resolved
@goccy
Copy link
Owner

goccy commented Aug 19, 2021

The latest test has failed. Probably this issue will be fixed by merging the master branch for tracking upstream.

@quentinmit
Copy link
Contributor Author

The latest test has failed. Probably this issue will be fixed by merging the master branch for tracking upstream.

Would you prefer a merge commit or a rebase?

@goccy
Copy link
Owner

goccy commented Aug 19, 2021

Would you prefer a merge commit or a rebase?

Either of them is ok 👍

@quentinmit
Copy link
Contributor Author

Sorry for the delay, I merged in the current masster.

@goccy goccy merged commit 864ce75 into goccy:master Aug 25, 2021
@quentinmit quentinmit deleted the duration branch November 30, 2021 10:58
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.

3 participants