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

add specific exception for time jumping backwards #492

Merged
merged 1 commit into from
Oct 23, 2014
Merged

add specific exception for time jumping backwards #492

merged 1 commit into from
Oct 23, 2014

Conversation

jowave
Copy link

@jowave jowave commented Aug 19, 2014

reason: ROS shutdown and time jumps should be distinguishable.
ROSTimeMovedBackwardsException inherits from ROSInterruptException
to preserve the API.
fixes #485

@jowave
Copy link
Author

jowave commented Aug 19, 2014

Recreated the pull request against indigo-devel.
Sorry for the inconvenience.

@ros-pull-request-builder
Copy link
Member

Can one of the admins verify this patch?

@dirk-thomas
Copy link
Member

@dirk-thomas
Copy link
Member

Can you please move the exception class to clients/rospy/src/rospy/exceptions.py where most other exceptions are defined.

Beside this minor detail the patch lgtm.

@jowave
Copy link
Author

jowave commented Sep 15, 2014

I moved the exception and updated the pull request.

@dirk-thomas
Copy link
Member

@ros-pull-request-builder
Copy link
Member

Test failed.
Refer to this link for build results: http://jenkins.ros.org/job/_pull_request-indigo-ros_comm/121/

@dirk-thomas
Copy link
Member

Please update your patch to pass all unit tests. It currently breaks 145 tests.

@dirk-thomas
Copy link
Member

Please update your patch to pass all unit tests. It currently breaks 145 tests.

@ros-pull-request-builder
Copy link
Member

Test passed.
Refer to this link for build results: http://jenkins.ros.org/job/_pull_request-indigo-ros_comm/131/

@jowave
Copy link
Author

jowave commented Oct 16, 2014

I have updated the patch. Apparently it passed the tests now.

@wjwwood
Copy link
Member

wjwwood commented Oct 16, 2014

+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")
Copy link
Member

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.

@jowave
Copy link
Author

jowave commented Oct 17, 2014

I added the time offset in the error message and a small test for the exception.

@ros-pull-request-builder
Copy link
Member

Test passed.
Refer to this link for build results: http://jenkins.ros.org/job/_pull_request-indigo-ros_comm/134/

@tlind
Copy link

tlind commented Oct 18, 2014

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

try:
    r.sleep()
except rospy.exceptions.ROSInterruptException as e:
    if e.message == "ROS time moved backwards":
        rospy.logwarn("Time has moved backwards (probably ROS clock has been reset)!")

However, it seems that supplying the time offset as an additional argument to the exception constructor will break that message:

>>> print rospy.exceptions.ROSInterruptException("ROS time moved backwards").message
ROS time moved backwards
>>> print rospy.exceptions.ROSInterruptException("ROS time moved backwards", -10.0).message
[empty string]

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.

@dirk-thomas
Copy link
Member

@tlind That is a good point.

@jowave Can you please update the new exception class to store the time offset in a member variable and keep the message of the exception as-is.

@ros-pull-request-builder
Copy link
Member

Test passed.
Refer to this link for build results: http://jenkins.ros.org/job/_pull_request-indigo-ros_comm/135/

@jowave
Copy link
Author

jowave commented Oct 20, 2014

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
Copy link
Member

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.

@dirk-thomas
Copy link
Member

Please squash your commits after removing the unnecessary pass line.

reason: ROS shutdown and time jumps should be distinguishable.
ROSTimeMovedBackwardsException inherits from ROSInterruptException
to preserve the API.
fixes #485
@ros-pull-request-builder
Copy link
Member

Test passed.
Refer to this link for build results: http://jenkins.ros.org/job/_pull_request-indigo-ros_comm/138/

@dirk-thomas
Copy link
Member

Thank you for you efforts on this. Merging...

dirk-thomas added a commit that referenced this pull request Oct 23, 2014
add specific exception for time jumping backwards
@dirk-thomas dirk-thomas merged commit 4d2b423 into ros:indigo-devel Oct 23, 2014
@jowave
Copy link
Author

jowave commented Oct 24, 2014

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?

@dirk-thomas
Copy link
Member

No worries. The Jenkins check is still experimental. We hopefully can improve that in the future.

@jowave jowave deleted the rospy_sleep_time_backwards branch November 26, 2014 07:44
@@ -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)
Copy link
Contributor

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.

Copy link
Member

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

peci1 added a commit to peci1/ros_comm that referenced this pull request Apr 6, 2017
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.
rsinnet pushed a commit to MisoRobotics/ros_comm that referenced this pull request Jun 19, 2017
add specific exception for time jumping backwards
sputnick1124 pushed a commit to sputnick1124/ros_comm that referenced this pull request Jul 30, 2017
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.
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.

6 participants