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

Return a non 0 exit code on error #323

Open
Morgimiel opened this issue Sep 18, 2024 · 4 comments
Open

Return a non 0 exit code on error #323

Morgimiel opened this issue Sep 18, 2024 · 4 comments
Assignees
Labels
enhancement New feature or request priority/review size/M Denotes an issue/PR requiring a relatively moderate amount of work
Milestone

Comments

@Morgimiel
Copy link

Morgimiel commented Sep 18, 2024

Is this RFE related to an Existing Problem? If so, please describe:

I have a script that load images to hauler store. If something went wrong, I have no error exit code to early exit my script.

Describe Proposed Solution(s):

We should have an exit code > 0 if something went wrong during a process.
For exemple, my hauler store add image command fails because of a bad credentials but I still have exit code 0.

Describe Possible Alternatives:

Additional Context:

@Morgimiel Morgimiel added the enhancement New feature or request label Sep 18, 2024
@zackbradys zackbradys added this to the Hauler v1.1.x milestone Sep 21, 2024
@zackbradys zackbradys self-assigned this Sep 21, 2024
@dweomer
Copy link
Contributor

dweomer commented Sep 23, 2024

Looks like you may have been bit by this recent change:

I think the resolution to should be a flag/envvar that kicks Hauler into the "legacy" fail-fast mode. Something like --failfast with a default of false with value of $HAULER_FAILFAST parsed for truthiness as env override.


@Morgimiel can you provide a simple example of a script that you expect to fail but does not?

@Morgimiel
Copy link
Author

Morgimiel commented Sep 24, 2024

I agree with your proposal. A flag to optionnally fail on error seems OK to me.
My script is pretty simple:

helm template myproject | grep image: | tr -d ' "' | sed -nr 's/^image:(.*)$/\1/p' | sort -u | xargs -I {} hauler store add image {}

I want it to fail if any of the add image command fails.

PS: It would be a great feature to have hauler store add chart command have an option to find docker images within in and add them to the store :D. But thats purely bonus ;)

@GDWR
Copy link

GDWR commented Oct 10, 2024

I'd also greatly appreciate a non-zero code too.
In my script I'm having to utilise logs to determine a failure, my usage can be seen below.

echo "Adding docker images (this will take a while)"
IMAGES="$(docker compose config --images 2>/dev/null)"
for image in ${IMAGES} ; do
  # Hauler doesn't exit with non-zero status code on failure, so we use the log content to determine a failure...
  # https://github.com/hauler-dev/hauler/issues/323
  hauler store add image $image --platform linux/amd64 | tee /dev/tty | grep -q "successfully added 'image'"
  if [ $? -ne 0 ]; then
    echo "error: Failed to add image $image to hauler store" >&2
    exit 1
  fi
done

@zackbradys
Copy link
Member

Hey @Morgimiel and @GDWR, thank you both for providing the additional context... we will be changing back to the expected/defaulted behavior and providing a flag for each relevant command as @dweomer mentioned earlier

@zackbradys zackbradys added size/M Denotes an issue/PR requiring a relatively moderate amount of work priority/review labels Oct 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request priority/review size/M Denotes an issue/PR requiring a relatively moderate amount of work
Projects
Status: Pending Review
Development

No branches or pull requests

4 participants