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

Respect exit codes with --exec-batch #1137

Merged
merged 1 commit into from
Nov 1, 2022

Conversation

amesgen
Copy link
Contributor

@amesgen amesgen commented Oct 13, 2022

Closes #1136

@@ -196,14 +198,20 @@ impl CommandBuilder {
fn finish(&mut self) -> io::Result<()> {
if self.count > 0 {
self.cmd.try_args(&self.post_args)?;
self.cmd.status()?;
if !self.cmd.status()?.success() {
self.exit_code = ExitCode::GeneralError;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rather than storing an exit code here, I think we should return an 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.

Hmm, my idea went like this: We do not want to short-circuit on non-success exit codes (compare -x semantics), so we were to return an Err, we would have to catch it (but just this one, not other Errs) in execute_batch and still maintain sth like this exit_code there. But this seemed just more convoluted, so I took this approach.

Happy to change though if you have a different idea 👍

Copy link
Collaborator

Choose a reason for hiding this comment

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

The way -x works is if a command fails, we short circuit for that particular path.

So for example if you have fd foo -x c1 \; -x c2 and c1 fails for a specific path, then c2 won't be run for that path. But it will continue trying to run c1 for other paths

I think we would probably want similar behavior for exec-batch. If one command fails, we probably don't want to run the next one in the series, because it might depend on the first one succeeding.

However, maybe we do want to run the commandset with the next batch of paths if we have more paths than can fit in a single command invocation?

I created #1138 which will short circuit.

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 was actually only thinking about batching in my comment above, thanks for mentioning multiple commands.

However, maybe we do want to run the commandset with the next batch of paths if we have more paths than can fit in a single command invocation?

Yes, I think that we should run either all or no batches of any given command, to be consistent with -x (where one can be sure that a command is either executed for all files or for none).


So in short, it seems reasonable to have short circuiting for mulitple commands, but no short circuiting for multiple batches of the same command.

I can update this PR if you agree, but if short circuiting batches is prefered, then #1138 seems nicer 👍

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't have a very strong preference on whether or not we short circuit for batches for a single command. @sharkdp do you have any thoughts on it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah.... I didn't think about that. Now I think 3 might be the right way to go, at least for batches.

Or possibly we change the way batches work, and we run all batches for each command before moving on to the next one, but that could hurt performance.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Or possibly we change the way batches work, and we run all batches for each command before moving on to the next one, but that could hurt performance.

That's not a bad idea, but it's probably material for another PR :). I don't think the perf impact would be too bad

Copy link
Owner

Choose a reason for hiding this comment

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

Okay. So how do we proceed with this PR? I think it would be great to add some tests for the batch-behavior as well. We can use --batch-size=N for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I understand it correctly that the semantics of this PR (no short circuiting at all, i.e. @sharkdp option 3.) are good for now? In that case, I will add a few tests ensuring that all commands are executed even if only some commands/batches fail 👍

Copy link
Owner

Choose a reason for hiding this comment

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

@amesgen That would be great

self.cmd.status()?;
if !self.cmd.status()?.success() {
self.exit_code = ExitCode::GeneralError;
}

self.cmd = Self::new_command(&self.pre_args)?;
self.count = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we do go with this approach, then I think we might need to reset the exit code here

@sharkdp
Copy link
Owner

sharkdp commented Nov 1, 2022

I'm going to merge this as-is, because it's definitely better than what we have on master. If you feel like adding those tests later @amesgen, that would be very much appreciated. But please don't feel obliged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression: --exec-batch no longer preserves status code
4 participants