From f38c6e00ec0568c31d12b725ed0ec889067df17c Mon Sep 17 00:00:00 2001 From: ChrisCarini <6374067+ChrisCarini@users.noreply.github.com> Date: Sat, 23 Jan 2021 17:52:23 -0800 Subject: [PATCH] Add a nice message for generic error capturing. Each known error now has a specific error code, and any unknown errors will have an error banner printed asking the viewer to open an issue on GitHub against this GitHub Action. Resolves #15 --- entrypoint.sh | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 9e6f700..26f677c 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -22,7 +22,7 @@ set -o errexit set -o nounset ## -# GitHub Debug Function +# GitHub Debug Functions ## gh_debug() { if [[ "$#" -eq 0 ]] ; then @@ -34,6 +34,34 @@ gh_debug() { fi } +# Note: We can *NOT* pass `$LINENO` into the trap, as the `EXIT` trap always shows the line being '1'. Yes, even +# if it shows something else on your development machine. :( +trap 'exit_trap $?' EXIT +exit_trap() { + gh_debug "Script exited with status code [$1]." + case $1 in + 0) gh_debug "Everything went as desired. Goodbye." ;; + 64) echo "::error::Exiting due to a known, handled exception - duplicate ide-version entries found." ;; + 65) echo "::error::Exiting due to a known, handled exception - invalid download headers when downloading an IDE." ;; + 66) echo "::error::Exiting due to a known, handled exception - invalid zip file downloaded." ;; + 67) echo "::error::Exiting due to a known, handled, plugin validation failure." ;; + 68) echo "::error::Exiting due to an unhandled plugin validation failure." ;; + + *) cat <> $post_loop_messages - exit 1 # An error has occurred - invalid download headers. + exit 65 # An error has occurred - invalid download headers. fi # Restore 'exit on error', as the test is over. set -o errexit @@ -335,7 +363,7 @@ EOF EOF # Print the message once in this log group, and then save for after so it's more visible to the user. echo "$message" ; echo "$message" >> $post_loop_messages - exit 1 # An error has occurred - invalid zip file. + exit 66 # An error has occurred - invalid zip file. fi # Restore 'exit on error', as the test is over. set -o errexit @@ -425,7 +453,7 @@ error_wall() { echo "::error::=== ===" echo "::error::==============================================" echo "::error::==============================================" - exit 1 # An error has occurred - plugin verification failure. + exit 67 # An error has occurred - plugin verification failure. } # Validate the log; fail if we find compatibility problems. @@ -501,7 +529,7 @@ elif [ ${VERIFICATION_SUCCESSFUL} == 1 ]; then echo "::error::===-------------------------------------------------===" echo "::error::=== Bug URL: https://github.com/ChrisCarini/intellij-platform-plugin-verifier-action/issues/new?labels=enhancement%2C+unknown-failure&template=unknown-failure-during-verification-check.md&title=Unknown+Failure+Identified%21" echo "::error::===-------------------------------------------------===" - exit 1 # An error has occurred - plugin verification failure. + exit 68 # An error has occurred - plugin verification failure. else # We end the block here, nothing else would have ended it. echo "::endgroup::" # END "Running validations against output..." block.