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

A better handler for ./coreutils date -f aze #4482

Merged
merged 8 commits into from
Mar 18, 2023
Merged

Conversation

AbhinavMir
Copy link
Contributor

@AbhinavMir AbhinavMir commented Mar 9, 2023

./target/release/coreutils date -f aze doesn't result in panic anymore, instead gives Error: File not found at path . Fixes #4480

@AbhinavMir AbhinavMir changed the title Fixes #4480 Fixes https:/uutils/coreutils/issues/4480 Mar 9, 2023
@AbhinavMir AbhinavMir changed the title Fixes https:/uutils/coreutils/issues/4480 A better handler for ./coreutils date -f aze Mar 9, 2023
}
Err(_) => {
eprintln!("Error: File not found at path {:?}", path);
Box::new(std::iter::empty())
Copy link
Contributor

Choose a reason for hiding this comment

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

could you please add a test to make sure we don't regress ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, the tests should go in test_date.rs right? Can't see a test for file stuff on there.

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah

Box::new(iter)
}
Err(_) => {
eprintln!("Error: File not found at path {:?}", path);
Copy link
Contributor

Choose a reason for hiding this comment

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

please use the same wording as GNU

$ LANG=C date -f file-non-existing
date: file-non-existing: No such file or directory

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I think the syntax should be like:

if path.metadata().is_err() {
return Err(USimpleError::new(
2,
format!("{}: No such file or directory", name.maybe_quote()),
));
};

and the error code should be 1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad! Fixed :)

Copy link
Contributor

Choose a reason for hiding this comment

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

this isn't resolved ;) see my second comment (using USimpleError)

Copy link
Contributor Author

@AbhinavMir AbhinavMir Mar 9, 2023

Choose a reason for hiding this comment

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

Aye! Sorry!

Would this work? I'm sorry for bugging you, just new to GNU contributions!

Err(err) => {return Err(USimpleError::new(2, format!("failed to open {}: {}", path.display(), err),));}

Copy link
Contributor

Choose a reason for hiding this comment

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

please try
but the error message isn't the one I asked you to update ;)

@sylvestre
Copy link
Contributor

and please fix the clippy warning

@github-actions
Copy link

github-actions bot commented Mar 9, 2023

GNU testsuite comparison:

Congrats! The gnu test tests/misc/tee is no longer failing!

@AbhinavMir
Copy link
Contributor Author

Error code now: date: aze: No such file or directory
Tests: All passed (added one for testing valid and then one for testing invalid files)
Clippy: No warnings

@github-actions
Copy link

github-actions bot commented Mar 9, 2023

GNU testsuite comparison:

Congrats! The gnu test tests/rm/rm2 is no longer failing!
GNU test failed: tests/tail-2/inotify-dir-recreate. tests/tail-2/inotify-dir-recreate is passing on 'main'. Maybe you have to rebase?

.fails();
result.no_stdout();
// should fail
assert!(result.stderr_str().starts_with("date: "));
Copy link
Contributor

Choose a reason for hiding this comment

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

please test the error message too here

@@ -204,7 +204,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
return set_system_datetime(date);
} else {
// Declare a file here because it needs to outlive the `dates` iterator.
let file: File;
let _file: File;
Copy link
Contributor

Choose a reason for hiding this comment

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

why this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To keep clippy happy, seems it was only being used for the previous implementation, should I keep it as is?

Copy link
Member

Choose a reason for hiding this comment

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

Surprisingly, it's even unnecessary in the old code :) Seems like the original implementor just assumed that it was necessary even though the BufReader::new and all the other functions take owned values to file isn't dropped anyway. So yeah, let's remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, great! Thx!

Copy link
Contributor

Choose a reason for hiding this comment

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

why you didn't remove it ? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, no particular reason. Let me remove it then.

let lines = BufReader::new(file).lines();
let iter = lines.filter_map(Result::ok).map(parse_date);
Box::new(iter)
match File::open(path) {
Copy link
Contributor

Choose a reason for hiding this comment

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

rustfmt isn't happy :)

@@ -198,6 +198,27 @@ fn test_date_set_valid_2() {
}
}

#[test]
Copy link
Contributor

Choose a reason for hiding this comment

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

rustfmt isn't happy either

@AbhinavMir
Copy link
Contributor Author

Fixed fmt warnings. Anything else I missed?

@sylvestre sylvestre merged commit 89b83c2 into uutils:main Mar 18, 2023
@sylvestre
Copy link
Contributor

thanks :)

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.

date -f should better handle non existing files
3 participants