mina icon indicating copy to clipboard operation
mina copied to clipboard

run(:local) { command "..." } should abort on failure (or be removed)

Open jackc opened this issue 8 years ago • 2 comments

The local run environment does not check the results of its tasks.

  run(:local) do
    command "false"
    command "something-else"
  end

I would expect the task to be aborted and something-else not to run. Instead the error return code is ignored that something-else is run.

However, it is easy to work around. Given we are in rake we can use sh.

sh "false"
sh "something-else"

Given that sh is built-in, perhaps the best solution is to remove/deprecate run(:local) in favor of sh. Otherwise, perhaps it could be implemented in terms of sh instead of system.

jackc avatar Feb 28 '18 21:02 jackc

The deploy commands are all chained together with && as you can see when using mina deploy --simulate. But local commands are just placed inline.

My temporary fix is to do

run :local do
  command "something || exit 1"
  command "something else && another || exit 1"
end

But that's not very nice to look at, or have to remember. And if you try to use in_path then it will still bypass any failures because in_path wraps commands into a subprocess:

in_path("some/path") do
  command "echo first"
  command "false"
  command "echo last"
end

produces something like

...
(cd project/some/path && echo first && false && echo last && cd -)
another command
# "echo last" will not be called, but "another command" will

coreyworrell avatar Aug 29 '18 20:08 coreyworrell

My temporary fix is to do

run :local do
  command "something || exit 1"
  command "something else && another || exit 1"
end

What about the following?

run :local do
  command 'set -e'
  command 'something'
  command 'something else'
  command 'another'
end

See : The Set Builtin (Bash Reference Manual)

Even it is preferable to a behavior similar to rake's sh method (throwing exceptions to interrupt workflows a a default).

SwagDevOps avatar Sep 10 '20 21:09 SwagDevOps