0
$\begingroup$

Rosanswers logo

Hi there,

i've already looked into the roswiki and answers. Unfortunately answer.ros search gave me quite a lot of finding for Error and Service... :)

my question is related to failed service calls. Usually a service call returne true. But what if a service call fails. For instance the parameters sent where not valid or some function within the service throws an error.

In this case i would just return a boolean false within the service call and if i call this service by "rosservice call /service param1 param2" in the shell i get and error message:

ERROR: service [/service] responded with an error:

However I haven't seen any way to add an message to failed service call? Is there any way to do this?

cheers Mimax


Originally posted by Mimax on ROS Answers with karma: 174 on 2011-10-20

Post score: 2

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

Roscpp doesn't support passing error messages to the caller as far as I know. If that's possible for you, you can change the service definition to include an error code in the result. Then, instead of returning false from the service callback, you can fill in the error code and return true.

When using rospy, you can raise a ServiceException which contains an error message. That message is passed to a rospy client. You can find more information on that here.


Originally posted by Lorenz with karma: 22731 on 2011-10-20

This answer was ACCEPTED on the original site

Post score: 3


Original comments

Comment by Mimax on 2011-10-23:
Allright i do that know. I just wanted to wait to see whether there are any opinions during last weekend.

Comment by tfoote on 2011-10-23:
Please do remember to accept this answer before you forget about it so others know it answers your query. Just click the checkbox next to the thumbs up/down buttons.

Comment by Mimax on 2011-10-21:
Allright, i'll wait for some days and see whether there is any other input here and file a request.

Comment by Lorenz on 2011-10-20:
Not as far as I know, but you could file a feature request ticket at https://code.ros.org/trac/ros/

Comment by Mimax on 2011-10-20:
implement the ServiceException within roscpp? Well i could write a pythonbased service wrapper for my roscpp services ;)......

Comment by Mimax on 2011-10-20:
thanks for your answer. Unfortunately i'm using cpp. I could modify my return definitons... I also have thought about it.. but i don't like it since the service would return as true and i actually wanted to use a standardizes way of returning the error. do you know if there are any plans to

$\endgroup$
0
$\begingroup$

Rosanswers logo

Throw an exception inside your service callback function.

bool setCameraAttr(custom_msgs::CamSetAttrRequest &req, custom_msgs::CamSetAttrResponse &rsp) {
    throw std::runtime_error("this will show up"); 
}

->

ERROR: service [/host/ir/set_camera_attr] responded with an error: this will show up

Originally posted by xkortex with karma: 31 on 2021-02-04

This answer was NOT ACCEPTED on the original site

Post score: 3

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.