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

Regression: heroku run -x no longer returns correct exit code #2466

Closed
dzuelke opened this issue Aug 31, 2023 · 4 comments
Closed

Regression: heroku run -x no longer returns correct exit code #2466

dzuelke opened this issue Aug 31, 2023 · 4 comments

Comments

@dzuelke
Copy link

dzuelke commented Aug 31, 2023

Since 8.2.0:

$ heroku --version
heroku/8.1.9 darwin-x64 node-v16.19.0

$ heroku run -x -- 'bash -c "exit 2"' || echo $?  
Running bash -c "exit 2" on ⬢ sushi... up, run.6915 (Standard-1X)

 ›   Error: Process exited with code 2
 ›   Code: 2
2
$ heroku update --version 8.2.0


$ heroku --version             
heroku/8.2.0 darwin-x64 node-v16.19.0

$ heroku run -x -- 'bash -c "exit 2"' || echo $?
Running bash -c "exit 2" on ⬢ sushi... up, run.7202

Error: Process exited with code 2
1
$ heroku update


$ heroku --version
heroku/8.4.2 darwin-x64 node-v16.19.0

$ heroku run -x -- 'bash -c "exit 2"' || echo $?
Running bash -c "exit 2" on ⬢ sushi... up, run.2600 (Standard-1X)

Error: Process exited with code 2
1

Note: you have to use bash -c "exit 2" as the command; simply using exit 2 will terminate the shell and then the internal echo of the status code for later reading will not execute:

let command = this.opts['exit-code'] ? `${this.opts.command}; echo "\uFFFF heroku-command-exit-status: $?"` : this.opts.command
(the effective command is exit 2; echo "\uFFFF heroku-command-exit-status: $? vs bash -c "exit 2"; echo "\uFFFF heroku-command-exit-status: $?).

@k80bowman
Copy link
Contributor

k80bowman commented Aug 31, 2023

Thank you for all of the details on this, we are looking into it. In the meantime, for you or anyone else who runs into this issue, the workaround for now is to downgrade to version 8.1.9 using heroku update --version=8.1.9. We'll update this issue when we release a fix.

@dzuelke
Copy link
Author

dzuelke commented Aug 31, 2023

So, just an explanation of how this even works internally... when -x is passed to heroku run, the given command is suffixed with a special echo that returns $?, the exit status of the program:

let command = this.opts['exit-code'] ? `${this.opts.command}; echo "\uFFFF heroku-command-exit-status: $?"` : this.opts.command

This \uFFFF heroku-command-exit-status: … output is later detected and used:

let exitCode = data.match(/\uFFFF heroku-command-exit-status: (\d+)/m)
if (exitCode) {
debug('got exit code: %d', exitCode[1])
this.push(data.replace(/^\uFFFF heroku-command-exit-status: \d+$\n?/m, ''))
let code = Number.parseInt(exitCode[1])
if (code === 0) this.resolve()
else {
let err = new Error(`Process exited with code ${cli.color.red(code)}`)
err.exitCode = code
this.reject(err)
}
return
}

dzuelke added a commit to heroku/heroku-buildpack-php that referenced this issue Sep 1, 2023
@dzuelke
Copy link
Author

dzuelke commented Sep 1, 2023

Related: #2468

@dzuelke
Copy link
Author

dzuelke commented Sep 30, 2023

Confirmed fixed by #2467.

@dzuelke dzuelke closed this as completed Sep 30, 2023
dzuelke added a commit to heroku/heroku-buildpack-php that referenced this issue Sep 30, 2023
robinwo pushed a commit to robinwo/heroku-buildpack-php that referenced this issue Sep 13, 2024
robinwo pushed a commit to robinwo/heroku-buildpack-php that referenced this issue Sep 13, 2024
robinwo pushed a commit to robinwo/heroku-buildpack-php that referenced this issue Sep 13, 2024
robinwo pushed a commit to robinwo/heroku-buildpack-php that referenced this issue Sep 13, 2024
robinwo pushed a commit to robinwo/heroku-buildpack-php that referenced this issue Sep 13, 2024
robinwo pushed a commit to robinwo/heroku-buildpack-php that referenced this issue Sep 13, 2024
robinwo pushed a commit to robinwo/heroku-buildpack-php that referenced this issue Sep 13, 2024
robinwo pushed a commit to robinwo/heroku-buildpack-php that referenced this issue Sep 13, 2024
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

No branches or pull requests

2 participants