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

Regression in parsing Duration flag #333

Closed
linki opened this issue Feb 8, 2023 · 5 comments
Closed

Regression in parsing Duration flag #333

linki opened this issue Feb 8, 2023 · 5 comments

Comments

@linki
Copy link

linki commented Feb 8, 2023

#329 introduced a difference in parsing a DurationVar compared to the old version.

Unfortunately, this breaks the old behaviour when the duration was a negative value. The most common use case is probably to have a Default("-1s") to denote that the value isn't set at all. Similarly a --some-duration="" would previously fail but is now treated as 0s. Here are the differences that I can observe:

// parse negative duration
time.ParseDuration("-1s") => `-1s` // no error
str2duration.Str2Duration("-1s") => `(*errors.errorString)(0x140001c2b70)(invalid input duration string)`
// parse empty string
time.ParseDuration("") => `(*errors.errorString)(0x140001c2b80)(time: invalid duration "")`
str2duration.Str2Duration("") => 0s // no error

In practice this leads to the following (some-duration is a DurationVar).

// old version (v2.2.6)
$ go run main.go --some-duration="-1s"
... // runs fine

// new version (v2.3.1 (2e61e1e))
$ go run main.go --some-duration="-1s"
main: error: invalid input duration string, try --help
exit status 1
// old version (v2.2.6)
$ go run main.go --some-duration=""
main: error: time: invalid duration "", try --help
exit status 1

// new version (v2.3.1 (2e61e1e))
$ go run main.go --some-duration=""
... // runs fine

/cc @adowair

@SuperQ
Copy link

SuperQ commented Mar 7, 2023

This also seems to be breaking our 32-bit testing. See: prometheus/node_exporter#2622

@SuperQ
Copy link

SuperQ commented Mar 7, 2023

It looks like the v2 of this library may fix the issues.

@alecthomas, can you cut a new tag with #336?

@alecthomas
Copy link
Owner

👍

@alecthomas
Copy link
Owner

Tagged 2.3.2

@linki
Copy link
Author

linki commented Apr 17, 2023

2.3.2 fixed it for me: linki/chaoskube@c4b9b0d

Thank you @alecthomas and @SuperQ 🙏

@linki linki closed this as completed Apr 17, 2023
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

No branches or pull requests

3 participants