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

How to get error information using roslibjs

asked 2015-05-11 20:12:45 -0500

Joseph Landau gravatar image

Using roslibjs and rosbridge--I'd like to get more information when there is an error, particularly when connecting. My code is:

ros = new ROSLIB.Ros({
url: robotUrl

ros.on('error', function(error) { console.log ('Error connecting to websocket server: ' , error); });

When an error occurs, I see in the debugger that the variable "error" contains a very involved structure, and I guess the actual error message is in there somewhere, but where?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2015-05-12 09:33:49 -0500

rtoris288 gravatar image

updated 2015-05-12 09:34:12 -0500

The error variable is should always be a string. You can concatenate it in the console.log statement and it should work.

edit flag offensive delete link more


When I concatenate the error variable (here's the code): "console.log ('Error connecting to websocket server: ' + error);", the result is: "Error connecting to websocket server: [object Event]" Looks like the argument called error is an Event rather than a string?

Joseph Landau gravatar image Joseph Landau  ( 2015-05-12 12:36:31 -0500 )edit

Strange, what if you just log the error variable by itself? console.log(error);, this is based off a working example:

rtoris288 gravatar image rtoris288  ( 2015-05-12 13:17:34 -0500 )edit

In that case, I get: "Event {path: Array[0], cancelBubble: false, returnValue: true, srcElement: WebSocket, defaultPrevented: false…}" This is clickable and expands to show lots of properties. Incidentally, the debugger shows that roslib.js (line 651?) has the message. Or, at least, a message.

Joseph Landau gravatar image Joseph Landau  ( 2015-05-12 19:10:12 -0500 )edit

Question Tools

1 follower


Asked: 2015-05-11 20:12:45 -0500

Seen: 692 times

Last updated: May 12 '15