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

fix(rm): ignore NotFound errors when --force flag is set #93

Merged
merged 6 commits into from
Jan 15, 2023

Conversation

pkedy
Copy link
Contributor

@pkedy pkedy commented Jan 15, 2023

This PR adds a try/catch inside executeRemove and ignores NotFound errors when force is set.

This is inline with the behavior of rm -Rf on Unix.

Copy link
Owner

@dsherret dsherret left a comment

Choose a reason for hiding this comment

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

Thanks @pkedy! Would you be able to add a test to mod.test.ts for this under "test remove" to ensure we don't get a regression in the future?

);
}

return Deno.remove(path, { recursive: flags.recursive });
Copy link
Owner

Choose a reason for hiding this comment

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

I believe it should just be a try/catch around this Deno.remove only so it doesn't exit if one of the paths fails?

Maybe just:

return Deno.remove(path, { recursive: flags.recursive }).catch(err => {
  if (flags.force && err instanceof Deno.errors.NotFound) {
    return Promise.resolve();
  } else {
    return Promise.reject(err);
  }
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried the try/catch around the Deno.remove and the exception still bubbled up. Your snippet with catch looks promising and worth a try though. I'll also see about adding a test.

Thanks for this project, BTW. I needed something like shx for Deno in our code generation project called Apex and this fits the bill!

Copy link
Owner

Choose a reason for hiding this comment

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

That project looks really useful.

Adding test for rm -Rf. (not sure what the windows error message will be expecting failed test in CI).
@pkedy
Copy link
Contributor Author

pkedy commented Jan 15, 2023

@dsherret I added the test. Pls approve the workflow to run. I'm expecting the test to fail on Windows because I don't know how the OS error from Deno.remove will be formatted. If that is the case, feel free to edit my branch to move this along. It would be great to get this in a release.

@dsherret
Copy link
Owner

I have a Windows machine. I'll fix it locally on Windows then push to the PR.

Copy link
Owner

@dsherret dsherret left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @pkedy! I will do a release later today.

@dsherret dsherret changed the title rm command: Ignore NotFound errors when force flag is set fix(rm): ignore NotFound errors when --force flag is set Jan 15, 2023
@dsherret dsherret merged commit 2fee64b into dsherret:main Jan 15, 2023
@pkedy pkedy deleted the rm_force_ignore_not_found branch January 16, 2023 17:19
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.

None yet

2 participants