-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
fix: match date -I error messages with GNU date #4499
Conversation
panic isn't the right approach to manage a user facing error. With your change:
it should be like GNU:
See https:/uutils/coreutils/blob/main/src/uu/date/src/date.rs#L249-L253 as example Also, it will need a test to make sure we don't regress |
@shanmukhateja are you still working on it ? :) |
@sylvestre Yes I plan on working on it except I'm not sure how to implement SimpleError struct inside FromStr which returns Self. In the case of panic, it halts the execution but now when I try using the struct, it complaints of trying to return Result. Thoughts? |
You should try a bit more :) |
Have you seen my comment in the issue? You probably don't need to change this function, just make sure that clap gives an error before we even get here. |
@sylvestre @tertsdiepraam I used Note: unit test is missing. Success case: $ cargo run date -Idate
Finished dev [unoptimized + debuginfo] target(s) in 0.33s
Running `target/debug/coreutils date -Idate`
2023-03-15
$ cargo run date -Ihour
Finished dev [unoptimized + debuginfo] target(s) in 0.31s
Running `target/debug/coreutils date -Ihour`
2023-03-15T21+05:30 Error case: $ cargo run date -I@
Finished dev [unoptimized + debuginfo] target(s) in 0.31s
Running `target/debug/coreutils date '-I@'`
error: '@' isn't a valid value for '--iso-8601 <FMT>'
[possible values: date, hour, hours, minute, minutes, ns]
For more information try '--help' |
look great :) |
src/uu/date/src/date.rs
Outdated
@@ -115,7 +115,7 @@ impl<'a> From<&'a str> for Iso8601Format { | |||
NS => Self::Ns, | |||
DATE => Self::Date, | |||
// Should be caught by clap | |||
_ => panic!("Invalid format: {s}"), | |||
_ => panic!("date:` invalid argument `{s}` for '--iso-8601'"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe
_ => panic!("date:` invalid argument `{s}` for '--iso-8601'"), | |
_ => unreachable!(), |
if we won't go there then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ping ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, this commit 5e42b58
(#4499) fixes it.
Still missing the unit test. Will ping when I have it working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks
@sylvestre unit tests added. |
please add the tests here: |
- move unit test to test_date.rs - include `second(s)` as valid values for iso8601 argument
@sylvestre ..third time's the charm? |
thanks :) |
Thank you for being patient. @sylvestre |
oh, don't mention it :) |
Fixes #4494