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

Local task error or exit do not stop the script execution #267

Closed
Tofandel opened this issue Sep 26, 2023 · 3 comments
Closed

Local task error or exit do not stop the script execution #267

Tofandel opened this issue Sep 26, 2023 · 3 comments
Labels

Comments

@Tofandel
Copy link

Tofandel commented Sep 26, 2023

Envoy Version

2.8.6

Laravel Version

10.25.0

PHP Version

8.1

Database Driver & Version

No response

Description

Script lines of local task's which are failing are completely ignored and continues the script execution, which is a different behavior than a task executed via ssh

Steps To Reproduce

@servers(['local' => 'localhost'])

@task('transfer', ['on' => 'local'])
foo
echo $?
(echo "test" && exit 1)
echo $?
echo "Oops"
@endtask

Output

vendor/bin/envoy run transfer
[localhost]: sh: 1: foo: not found
[localhost]: 127
[localhost]: test
[localhost]: 1
[localhost]: Oops

Only a direct exit 1; outside of parentesis seems to stop the rest of the execution

So the workaround seems to be adding || exit $? after each line in a script, or starting the local scripts with set -e

@Tofandel
Copy link
Author

Tofandel commented Sep 26, 2023

A possible fix would then be

  $isWin = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';

  if (in_array($target, ['local', 'localhost', '127.0.0.1'])) {
      $process = Process::fromShellCommandline($isWin ? $task->script : 'set -e'.PHP_EOL.$task->script, null, $env);
  }

@driesvints driesvints added the bug label Sep 28, 2023
@driesvints
Copy link
Member

Thanks @Tofandel. Can you PR that change so Taylor can have a look?

@driesvints
Copy link
Member

Closing this issue because it's inactive, already solved, old or not relevant anymore. Feel to open up a new issue if you're still experiencing this.

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

No branches or pull requests

2 participants