def assert_error_code_equals(self, code1, code2): self.assertEqual( code1, code2, "Error codes do not match: '%s' vs '%s'! " % (RLLErrorCode(code1), RLLErrorCode(code2)), )
def test_0_error_codes(self): e_ok = RLLErrorCode(RLLErrorCode.SUCCESS) e_invalid = RLLErrorCode(RLLErrorCode.INVALID_INPUT) e_recoverable = RLLErrorCode(RLLErrorCode.RECOVERABLE_FAILURE) e_critical = RLLErrorCode(RLLErrorCode.CRITICAL_FAILURE) def check_code(error_code, success, failure, recoverable, invalid): self.assertEqual(error_code.succeeded(), success) self.assertEqual(error_code.failed(), not success) self.assertEqual(error_code.is_critical_failure(), failure) self.assertEqual(error_code.is_recoverable_failure(), recoverable) self.assertEqual(error_code.is_invalid_input(), invalid) # basic checks to validate the ErrorCode class check_code(e_ok, True, False, False, False) check_code(e_invalid, False, False, False, True) check_code(e_recoverable, False, False, True, False) check_code(e_critical, False, True, False, False)
def __init__(self, execute=None, verbose=True): self.verbose = verbose RLLBasicMoveClient.__init__(self) RLLMoveClientListener.__init__(self, execute) self.get_start_goal_srv = rospy.ServiceProxy('get_start_goal', GetStartGoal) self.move_srv = rospy.ServiceProxy('move', Move) self.check_srv = rospy.ServiceProxy('check_path', CheckPath, persistent=True) RLLErrorCode.set_error_code_details( RLLErrorCode.PROJECT_SPECIFIC_RECOVERABLE_1, "PREVIOUS_MOVE_FAILED", "A previous move service call failed. As a result all further move" " service calls will be rejected. Please verify that a movement is" " possible by calling check_path first.") RLLErrorCode.set_error_code_details( RLLErrorCode.PROJECT_SPECIFIC_INVALID_1, "TOO_LITTLE_MOVEMENT", "Requests that cover a distance between 0 and 5 mm or sole " "rotations less than 20 degrees are not supported!") RLLErrorCode.set_error_code_details( RLLErrorCode.PROJECT_SPECIFIC_INVALID_2, "NO_PATH_FOUND", None) override_formatting_for_ros_types()
def _handle_response_error_code(self, srv_name, resp): name = ansi_format(srv_name, C_NAME) if resp.success: if self.verbose: rospy.loginfo("%s %ssucceeded%s", name, C_OK, C_END) return True error_code = RLLErrorCode(resp.error_code) if error_code.is_critical_failure(): rospy.logerr( "%s %sfailed critically with error: %s%s", name, C_FAIL, C_END, error_code) raise CriticalServiceCallFailure( error_code, "Service call %s failed with error: %s" % ( srv_name, error_code)) else: rospy.logwarn("%s %sfailed: %s%s", name, C_FAIL, C_END, error_code) if self._exception_on_any_failure: raise ServiceCallFailure( error_code, "Service call %s failed: %s" % (srv_name, error_code)) elif error_code.code == RLLErrorCode.JOB_EXECUTION_TIMED_OUT: raise ServiceCallFailure( error_code, "You exceeded the maximum job execution duration.") hint = error_code.get_hint() if hint is not None: rospy.loginfo("%sPossible failure reason:%s %s", C_INFO, C_END, hint) return False
def __init__(self): self.verbose = True self._exception_on_any_failure = False self._last_error_code = RLLErrorCode() self._logging_stream = rospy.logdebug