-
Notifications
You must be signed in to change notification settings - Fork 913
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
add specific exception for time jumping backwards #492
add specific exception for time jumping backwards #492
Conversation
Recreated the pull request against indigo-devel. |
Can one of the admins verify this patch? |
Can you please move the exception class to Beside this minor detail the patch lgtm. |
I moved the exception and updated the pull request. |
Test failed. |
Please update your patch to pass all unit tests. It currently breaks 145 tests. |
4533777
to
ebd9e49
Compare
Please update your patch to pass all unit tests. It currently breaks 145 tests. |
Test passed. |
I have updated the patch. Apparently it passed the tests now. |
+1 |
@@ -128,7 +131,8 @@ def sleep(duration): | |||
rostime_cond.wait(0.5) | |||
|
|||
if rospy.rostime.get_rostime() < initial_rostime: | |||
raise rospy.exceptions.ROSInterruptException("ROS time moved backwards") | |||
rospy.core.logerr("ROS time moved backwards") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please include the time offset in the error message so that the user has a better idea how much the time jumped.
I added the time offset in the error message and a small test for the exception. |
Test passed. |
I am worried that commit d934e53 might break existing code which is trying to catch the exception. Since there was previously no specific exception for this case, the only way of specifically catching the time-moved-backwards issue was to check the exception message, e.g.:
However, it seems that supplying the time offset as an additional argument to the exception constructor will break that message:
Might it be a better idea to only rospy.logerr() the time offset, and leave the exception message as-is? Or add an additional field to the exception class which contains the time offset? EDIT: I just read that Exception.message seems to be deprecated since 2.6, though I've been using it a few times and never saw a warning anywhere. Not sure how much other code depends on it. The correct way seems to be to use e.args[0], which returns the same result in both cases. |
Test passed. |
I modified the code to work with Exception.message and added a test to check for the right message. |
except ROSInterruptException as e: | ||
# ensure the message is not changed, because old code may check it | ||
self.assertEqual("ROS time moved backwards", e.message) | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line should be obsolete.
Please squash your commits after removing the unnecessary |
reason: ROS shutdown and time jumps should be distinguishable. ROSTimeMovedBackwardsException inherits from ROSInterruptException to preserve the API. fixes #485
Test passed. |
Thank you for you efforts on this. Merging... |
add specific exception for time jumping backwards
You're welcome. Thank you too. Edit: Hmm, the ros-pull-request-builder is answering. Should i not have replied to a closed pull request? |
No worries. The Jenkins check is still experimental. We hopefully can improve that in the future. |
@@ -128,7 +131,9 @@ def sleep(duration): | |||
rostime_cond.wait(0.5) | |||
|
|||
if rospy.rostime.get_rostime() < initial_rostime: | |||
raise rospy.exceptions.ROSInterruptException("ROS time moved backwards") | |||
time_jump = (initial_rostime - rospy.rostime.get_rostime()).to_sec() | |||
rospy.core.logerr("ROS time moved backwards: %ss", time_jump) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really needed to log the exception? I use ROS nodes together with Gazebo, where restarting the time is quite normal, and these messages start being annoying. The previous behavior also did not log the exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you that the log message is not strictly necessary. On the other hand this code has been integrated over two years ago and since then been released in three ROS distributions. Since no concerns were raised in the meantime I don't see the log message as a problem either.
Please feel free to create a pull request against the latest development branch (currently lunar-devel).
The log message doesn't make sense IMO, because there is still the exception being thrown. So the user can either catch it (and then he knows best whether it is an error or not), or he'll not catch it, and then he'll see the message printed in the stack trace. This is a followup of comment ros#492 (comment) . My use-case: I have a ROS node running alongside Gazebo, and resetting Gazebo always prints this error to the log, even if it is no error for me, since I expect the time to be restarted.
add specific exception for time jumping backwards
The log message doesn't make sense IMO, because there is still the exception being thrown. So the user can either catch it (and then he knows best whether it is an error or not), or he'll not catch it, and then he'll see the message printed in the stack trace. This is a followup of comment ros#492 (comment) . My use-case: I have a ROS node running alongside Gazebo, and resetting Gazebo always prints this error to the log, even if it is no error for me, since I expect the time to be restarted.
reason: ROS shutdown and time jumps should be distinguishable.
ROSTimeMovedBackwardsException inherits from ROSInterruptException
to preserve the API.
fixes #485