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

How can I ignore an error in a command? #660

Closed
mortoray opened this issue Jul 18, 2020 · 3 comments
Closed

How can I ignore an error in a command? #660

mortoray opened this issue Jul 18, 2020 · 3 comments

Comments

@mortoray
Copy link

There are some commands for which I want to ignore error returns and continue processing. Is there a way to mark a line as ignoring the return value?

This came up with killall which I used to end a process that may or may not be there. The current alternative I have is killall some_proce || true, though that seems like a bash thing, not a justfile thing.

@casey
Copy link
Owner

casey commented Jul 18, 2020

I think that currently, foo || true is the best way to do this. If you have a lot of commands you'd like to ignore errors for, you can switch to using a shebang recipe, which behaves like a normal shell script with respect to error codes, i.e. ignores them:

foo:
  #!/usr/bin/env sh
  cat bar

Make actually has a feature for this. If you put - in front of a command, it will ignore errors:

$ cat Makefile
foo:
  exit 1
$ make
exit 1
make: *** [foo] Error 1
$ cat Makefile
foo:
  -exit 1
$ make
exit 1
make: [foo] Error 1 (ignored)

It's a bit magical, but I wouldn't be opposed to adding this feature to Just. It would also make a great first issue for anyone interested.

iwillspeak added a commit to iwillspeak/just that referenced this issue Oct 3, 2020
Similar to `make` if a command is prefixed with `-` then the exit
status is ignored.

Fix for  casey#660
@iwillspeak
Copy link
Contributor

I've taken a stab at implemnting this feature in #687 .

iwillspeak added a commit to iwillspeak/just that referenced this issue Oct 3, 2020
Similar to `make` if a command is prefixed with `-` then the exit
status is ignored.

Fix for  casey#660
@casey
Copy link
Owner

casey commented Oct 3, 2020

This has been done! Thank you very much, @iwillspeak. I added some documentation in the readme, and cut v0.8.0 that includes the feature. Technically, this is a breaking change, which is why the minor version was bumped to 8, but I don't think it will be a problem in practice, since someone would have to have a recipe line starting with -.

@casey casey closed this as completed Oct 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants