ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
2

Error Message for failed Service Call

asked 2011-10-20 03:46:13 -0500

Mimax gravatar image

updated 2011-10-23 05:28:25 -0500

kwc gravatar image

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

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
3

answered 2011-10-20 20:30:41 -0500

Lorenz gravatar image

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.

edit flag offensive delete link more

Comments

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
Mimax gravatar image Mimax  ( 2011-10-20 21:17:42 -0500 )edit
implement the ServiceException within roscpp? Well i could write a pythonbased service wrapper for my roscpp services ;)......
Mimax gravatar image Mimax  ( 2011-10-20 21:22:55 -0500 )edit
Not as far as I know, but you could file a feature request ticket at https://code.ros.org/trac/ros/
Lorenz gravatar image Lorenz  ( 2011-10-20 21:23:19 -0500 )edit
Allright, i'll wait for some days and see whether there is any other input here and file a request.
Mimax gravatar image Mimax  ( 2011-10-21 00:04:52 -0500 )edit
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.
tfoote gravatar image tfoote  ( 2011-10-23 18:49:47 -0500 )edit
Allright i do that know. I just wanted to wait to see whether there are any opinions during last weekend.
Mimax gravatar image Mimax  ( 2011-10-23 21:12:08 -0500 )edit
3

answered 2021-02-04 17:48:45 -0500

xkortex gravatar image

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
edit flag offensive delete link more
0

answered 2023-05-25 07:40:27 -0500

SamH gravatar image

@Mimax I had the same issue where i was getting:

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

I found it was because i didn't have

return true;

at the end of my service function.

Also make sure you are setting

res.<service_response> = true;

in your service function otherwise your service will return "False" even when it has succeeded

edit flag offensive delete link more

Question Tools

Stats

Asked: 2011-10-20 03:46:13 -0500

Seen: 9,296 times

Last updated: May 25 '23