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

More fixes for error handling #103

Merged
merged 16 commits into from
Jan 18, 2017

Conversation

mathias-luedtke
Copy link
Member

@mathias-luedtke mathias-luedtke commented Jan 16, 2017

It turned out that #100 did not fix #99 completely.
error() did exit the travis-generated script as well.
Lesson learned: never exit from a sourced script.

So ci_main.sh does not get sourced anymore; environment is no longer exposed.
That's why I have added AFTER_SCRIPT.
Please note: Additional scripts added in .travis.yml do not get executed in docker container!

Travis executes all script: lines regardless of the exit code, but marks the build as failed if one line failed.
However, this might change: travis-ci/travis-ci#1066 (comment)

@mathias-luedtke
Copy link
Member Author

now it was easy to implement an exit code check (supersedes #80)

@mathias-luedtke mathias-luedtke force-pushed the error-handling branch 4 times, most recently from 3daabfa to a1276d1 Compare January 16, 2017 09:24
@mathias-luedtke
Copy link
Member Author

Perhaps AFTER_SCRIPT should only be executed in source_tests.sh (like BEFORE_SCRIPT).

@mathias-luedtke
Copy link
Member Author

rebased

@mathias-luedtke mathias-luedtke force-pushed the error-handling branch 4 times, most recently from 192f538 to cdb717c Compare January 17, 2017 00:49
if [ "$DEBUG_BASH" ] && [ "$DEBUG_BASH" == true ]; then set -x; fi
if [ $exit_code -ne "-1" ]; then exit $exit_code; fi
if [ $exit_code -ne "-1" ]; then ici_exit $exit_code; fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on situation, calling this function can fail where ici_exit is not yet loaded.

Copy link
Member Author

@mathias-luedtke mathias-luedtke Jan 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot think of a situation like this, do you have an example?
I can move ici_exitto the top if you prefer it..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a usecase for now, but only because this file is "util" we better address all the possibility we can think of.
Moving ici_exit sounds good to me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess ici_exit will be refactored to become the exit handler

@mathias-luedtke mathias-luedtke changed the title More fixes for error handling [WiP] More fixes for error handling Jan 17, 2017
@mathias-luedtke
Copy link
Member Author

Do not merge yet, I'd like to add error tracing and the error function needs to get modified for exit code propagation

@@ -86,15 +86,14 @@ function _end_fold_script {
color_wrap=${2:-32}

if [ $exit_code -eq "1" ]; then color_wrap=31; fi # Red color
if [ -z $TRAVIS_FOLD_NAME ]; then
if ! [ -z $TRAVIS_FOLD_NAME ]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this change is intended, the following else block may no longer make sense.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is intended, but the else block still makes sense.
if ! [ -z $TRAVIS_FOLD_NAME ] -> if $TRAVIS_FOLD_NAME is not empty -> if fold is open
This is the bug I did not find in #100

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. Turned out I've been consistently misunderstanding if -z option.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if [ -n $TRAVIS_FOLD_NAME ] ("not empty") might be easier to understand ^^

@@ -52,7 +52,7 @@ export HIT_ENDOFSCRIPT=false

source ${ICI_PKG_PATH}/util.sh

trap error ERR
trap error EXIT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to create a new function exit? Isn't trapping EXIT with error function misleading?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, will add this later

Copy link
Member

@130s 130s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tracking this down further! Seems like a tough one (reviewing this was too)!

Does this change require to change .travis.yml in users' repos, from like source .ci_config/travis.sh to .ci_config/travis.sh
(regardless, I agree in readme we no longer need to maintain the backward compatibility with the source usage)?

Perhaps AFTER_SCRIPT should only be executed in source_tests.sh (like BEFORE_SCRIPT).

Sorry but I can't remember why BEFORE_SCRIPT is run from source_tests.sh. Being called from ci_main.sh is more intuitive isn't it?

@mathias-luedtke
Copy link
Member Author

Does this change require to change .travis.yml in users' repos, from like source .ci_config/travis.sh to .ci_config/travis.sh

No, source travis.sh is still supported. We might add a warning in this case since the enviroment is not exported anymore

Sorry but I can't remember why BEFORE_SCRIPT is run from source_tests.sh

This way it is called after ROS and workspace set-up.

Perhaps AFTER_SCRIPT should only be executed in source_tests.sh (like BEFORE_SCRIPT).

I guess this will change with #98 anyway: It works for now, we should not touch it for now.

@130s
Copy link
Member

130s commented Jan 17, 2017

I see. +1 from me.
Minor todos can be addressed in the future in you like to merge this one first @ipa-mdl.

@mathias-luedtke mathias-luedtke force-pushed the error-handling branch 2 times, most recently from 907db28 to 9c39d51 Compare January 17, 2017 13:58
@mathias-luedtke mathias-luedtke force-pushed the error-handling branch 5 times, most recently from f33622a to e793265 Compare January 17, 2017 18:03
@mathias-luedtke mathias-luedtke changed the title [WiP] More fixes for error handling More fixes for error handling Jan 17, 2017
@mathias-luedtke mathias-luedtke force-pushed the error-handling branch 2 times, most recently from 963ff9e to 285b3ee Compare January 17, 2017 18:23
@mathias-luedtke
Copy link
Member Author

Error-code related refactoring completed :)
Now every fold lists an exit code and error forwards the exit code if possible.
ici_exit is the default exit handler and closes open folds

if [ -n $1 ]; then
echo "\e[31m$1\e0m" # print error in red
fi
if [ "$exit_code" == "0" ]; then # 0 is not error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this if block is added to handle mis-use? If so printing so would be friendly to the users?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exit_code is read from $?, which might be 0 in some cases, like if ! false ; then echo "$?"; fi.
So the following code works now as expected:

if ! [ -e "$my_path" ]; then
  error "path does not exist: '$my_path'"
fi

I think, the documentation needs to be updated..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternative implementation, with exit_code passing:

test -e "$my_path" || error "path does not exist: '$my_path'"

if [ $exit_code -ne "-1" ]; then exit $exit_code; fi
if [ "$exit_code" == "${EXPECT_EXIT_CODE:-0}" ]; then
exit 0
elif [ "$exit_code" == "0" ]; then # 0 was not expected
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is another use case.

If exit_code != EXPECT_EXIT_CODE then the exit_code will be used.
However, If exit_code is 0, but EXPECT_EXIT_CODE is not 0, the exit_code can not be returned as 0 would mean success.

@130s
Copy link
Member

130s commented Jan 17, 2017

Left a minor comment.

Now every fold lists an exit code and error forwards the exit code if possible.

That looks convenient!

@mathias-luedtke
Copy link
Member Author

mathias-luedtke commented Jan 17, 2017

If you do not object, I will merge this PR tomorrow morning (= in 10 hours) :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

travis.sh terminates travis job, no post-process script is run
2 participants