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

bug: ionosctl errors with exit code 1 if no images where found #406

Closed
hegerdes opened this issue Dec 1, 2023 · 2 comments · Fixed by #409
Closed

bug: ionosctl errors with exit code 1 if no images where found #406

hegerdes opened this issue Dec 1, 2023 · 2 comments · Fixed by #409
Assignees
Labels
bug Something isn't working

Comments

@hegerdes
Copy link

hegerdes commented Dec 1, 2023

Description

If you search/filter for a name that does not exists - the tool errors:

ionosctl image list --filters name=debian-12-amd64-latest-none-exist,location=txl,location=fra
echo $? # Outputs 1

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 0

Environment

Go Version:

?

Ionosctl version:

ionosctl version v6.7.1

OS:

Windows 11 Pro 23H2

Shell:

Git Bash

Configuration Files

None

How to Reproduce

If you search/filer for a name that does not exists - the tool errors:

ionosctl image list --filters name=debian-12-amd64-latest-none-exist,location=txl,location=fra
echo $? # Outputs 1

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

ionosctl image list --filters name=debian-12-amd64-latest,location=txl,location=fra
Error: error getting images based on given criteria

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 or kubectl

Also if you specify --output json it should also output an empty array/object. In case of an actual error - the output should also be json not text

References

@hegerdes hegerdes added the bug Something isn't working label Dec 1, 2023
@avirtopeanu-ionos
Copy link
Contributor

avirtopeanu-ionos commented Dec 4, 2023

Hi, thanks for your contribution!

  1. 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.

  2. --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!

@hegerdes
Copy link
Author

hegerdes commented Dec 4, 2023

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

avirtopeanu-ionos added a commit that referenced this issue Dec 5, 2023
* fix: empty result should return a zero status code

* test: fix tests

* fix: nil guards
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants