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

pathchk: use Results instead of writeln with stderr #5216

Closed
wants to merge 1 commit into from

Conversation

cakebaker
Copy link
Contributor

This PR uses eprintln! instead of passing stderr to writeln!. This makes it possible to remove #![allow(unused_must_use)].

@tertsdiepraam
Copy link
Member

Cool! I'm wondering whether these should be using our macros for printing with the util name though? Does GNU pathchk also write these without the util name?

@cakebaker
Copy link
Contributor Author

Good point, I will change it.

@sylvestre
Copy link
Contributor

@cakebaker ping ? :)

@cakebaker cakebaker changed the title pathchk: use eprintln instead of writeln w/ stderr pathchk: use Results instead of writeln with stderr Sep 23, 2023
@cakebaker
Copy link
Contributor Author

Refactored it to use UResult instead of bool so we can use USimpleError for the errors.

for p in paths.unwrap() {
let mut path = Vec::new();
for path_segment in p.split('/') {
path.push(path_segment.to_string());
}
res &= check_path(&mode, &path);
check_path(&mode, &path)?;
Copy link
Member

Choose a reason for hiding this comment

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

This now short circuits if an error occurs, is that the intended behaviour? Because if I try multiple bad paths in GNU, I get:

❯ pathchk "" ""
pathchk: '': No such file or directory
pathchk: '': No such file or directory

so it looks like it should not short-circuit. I think we can use the show! macro here, which will set the error code.

Also we should open an issue for the string handling here. It should operate on Path and OsStr instead of String I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, thanks. You also discovered a bug in our implementation because pathchk "" "" doesn't fail.

Copy link
Member

Choose a reason for hiding this comment

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

I made an issue for it!

@sylvestre
Copy link
Contributor

@cakebaker doesn't build anymore, sorry

Copy link
Contributor

@sylvestre sylvestre left a comment

Choose a reason for hiding this comment

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

needs the build to be fixed

@sylvestre
Copy link
Contributor

no activity for a while, closing

@sylvestre sylvestre closed this Sep 14, 2024
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