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

find: Changed exit code when an error is encountered in process_dir(). #352

Merged
merged 5 commits into from
Apr 8, 2024
Merged

Conversation

hanbings
Copy link
Collaborator

@hanbings hanbings commented Apr 6, 2024

fix: #27

Copy link

codecov bot commented Apr 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 59.52%. Comparing base (d94a8e9) to head (4d05816).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #352      +/-   ##
==========================================
+ Coverage   59.33%   59.52%   +0.18%     
==========================================
  Files          30       30              
  Lines        3819     3822       +3     
  Branches      869      869              
==========================================
+ Hits         2266     2275       +9     
+ Misses       1221     1218       -3     
+ Partials      332      329       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cakebaker
Copy link
Contributor

Can you please add a test to ensure we don't regress in the future?

@hanbings
Copy link
Collaborator Author

hanbings commented Apr 6, 2024

Can you please add a test to ensure we don't regress in the future?

OK, I've added a test for this fix.

src/find/mod.rs Outdated
@@ -149,10 +150,14 @@ fn process_dir<'a>(
// WalkDirIterator::skip_current_dir for explanation.
let mut it = walkdir.into_iter();
while let Some(result) = it.next() {
let mut matcher_io = matchers::MatcherIO::new(deps);
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason to move this here from the Ok case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry, I forgot to move it back into Ok().
My initial writing method was to write the error flag in matcher_io (which means matcher_io needs to be used in Err). Later, I found that it was designed as an immutable structure and then passed it as a parameter to the process_dir() function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changes have been committed in the latest. Thank you.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with your comment that using has_some_process_error is not a very elegant solution :)

I think you can eliminate the variable by using set_exit_code from uucore::error instead. It's what we use in coreutils in similar situations.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Looks better! Code has been reverted and uses uucore::error.
to be honest, I didn't know about this function before.

src/find/mod.rs Outdated
Comment on lines 205 to 207
if has_some_process_error {
return Err("There are some process errors.".into());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

GNU find doesn't show an error after the processing, it only shows the errors you show on line 157.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This code has been removed in the new commit. Thanks.

@cakebaker cakebaker merged commit d8e2ce2 into uutils:main Apr 8, 2024
18 checks passed
@cakebaker
Copy link
Contributor

Good work, 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.

Exit code unchanged when an error is encountered
2 participants