Closed hegerdes closed 11 months ago
Hi, thanks for your contribution!
Non-zero exit codes for empty API items
: I fully agree, this is a bug, code 0 should be returned if no images are found. I checked and same thing happens for a handful more resources (requests, etc) for which the same change will be applied. A valid use case should be checking for a zero status code and empty output to guarantee that you have no items of a certain resource.
--output json
should output an empty array: Here this would be a big impact / breaking change on scripts - I fully agree though, that this would make the most sense. I'll make a note to include this in the next major for sure, but can't guarantee it will happen too soon...
Thanks for opening this issue!
Workaround until this is fixed:
# Good old bash to the rescue...
if ionosctl image list --filters name=${IMG_NAME}-latest,location=txl,location=fra ; then
export CURRENT_IMG_RUN_IDS=$(ionosctl image list --filters name=${IMG_NAME}-latest,location=txl,location=fra --output json | jq -r ".items[].id")
echo $CURRENT_IMG_RUN_IDS
# Do stuff
fi
This does need a second request but that better then a failing CI
Description
If you search/filter for a name that does not exists - the tool errors:
This is and leads to unexpected behavior. A command should only error if there is anything wrong with the command/network/filesystem - not if the command return its expected outcome. For example in the CI. If there is no image the tool should output nothing and exit with 0. Or at leas there should be a flag for that.
Please apply to standard behavior
Expected behavior
Command returns nothing (or empty array if
json
output) and exits with code 0Environment
Go Version:
Ionosctl version:
OS:
Shell:
Configuration Files
None
How to Reproduce
If you search/filer for a name that does not exists - the tool errors:
This is and leads to unexpected behavior. A command should only error if there is anything wrong with the command/network/or - not if the command return its expected outcome. For example in the CI. If there is no image the tool should output nothing and exit with 0. Or at leas thee should be a flag for that.
Please apply to standard behavior
Error and Debug Output
Additional Notes
It is Industry standard to use non 0 exit codes if there is anything wrong - hears it behaves as expected. Most other tools also just exit with 0 when used with filter. See
docker ps --filter name=none-exist
orkubectl
Also if you specify
--output json
it should also output an empty array/object. In case of an actual error - the output should also bejson
not textReferences