podman-compose
podman-compose copied to clipboard
`podman-compose up` swallows exit code
Describe the bug
Related to #586 but for up
instead of build
.
podman-compose up
always returns a success result code, even when the command fails.
This is an issue, for example, in this script: if podman-compose up
fails, the script should error out (because it's set -e
) and not run podman-compose logs
on failed containers.
To reproduce, create this podman-compose.yml:
version: "3.5"
services:
container:
image: this-image-is-SO-unusable
And run these commands:
sudo podman-compose up || echo FAILED
echo result code: $?
"FAILED" should be printed after the podman-compose command, and podman claims the exit code should be 125:
Instead, "FAILED" is not printed, and the result code is 0: success!
Error: repository name must be lowercase
exit code: 125
podman start -a tmp_container_1
Error: unable to start container cad728e9678a340b717ef681b6a806d68432b28fcf1c138bc02eb1219c99f44c: netavark: setns: IO error: Operation not permitted (os error 1)
exit code: 125
result code: 0
Environment:
$ podman-compose version
['podman', '--version', '']
using podman version: 4.4.0-rc2
podman-composer version 1.0.3
podman --version
podman version 4.4.0-rc2
exit code: 0
- OS: Linux (Fedora Silverblue)
In my opinion proper exit codes are needed for any podman-compose command. But in that case, a complete rework of all commands relying on that 0 return value is needed. https://github.com/containers/podman-compose/issues/501#issuecomment-1160256390
Validated your bug and seems a issue.
But i only want to warn you for a mistake in the logic. If you use this in your actual scripts you get a "0" in all cases.
sudo podman-compose up || echo FAILED
echo result code: $?
"$?" will show the exit code of the last command. If compose fails you get the exit code of "echo".
$ cat /does_not_exist 2>/dev/null; echo $?
1
$ cat /does_not_exist 2>/dev/null || echo "does not exist"; echo $?
does not exist
0
Oops you’re absolutely right. Thanks for catching that!