Skip to content

Commit b1c57b0

Browse files
authored
Merge branch 'main' into fix_action_server
2 parents b6588c3 + 1014d4f commit b1c57b0

File tree

7 files changed

+28
-18
lines changed

7 files changed

+28
-18
lines changed

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ Authors
99
* Alexis Jeandeau `@jeandeaual <https://github.com/jeandeaual>`_
1010
* Hiroyuki Obinata `@obi-t4 <https://github.com/obi-t4>`_
1111
* Pedro Pereira `@MisterOwlPT <https://github.com/MisterOwlPT>`_
12+
* Domenic Rodriguez `@DomenicP <https://github.com/DomenicP>`_

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Unreleased
1818
* Switched to ``black`` for python code formatting.
1919
* Fix incompatible settings between ``black`` and ``flake8``.
2020
* Updated Github Actions workflows to remove python 3.6 builds.
21+
* Replaced occurrences of ``raise Exception`` with more specific ``Exception`` subclasses.
2122

2223
**Fixed**
2324

src/roslibpy/actionlib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def wait(self, timeout=None):
136136
Result of the goal.
137137
"""
138138
if not self.wait_result.wait(timeout):
139-
raise Exception("Goal failed to receive result")
139+
raise TimeoutError("Goal failed to receive result")
140140

141141
return self.result
142142

@@ -226,7 +226,7 @@ def __init__(
226226
self.wait_status = threading.Event()
227227

228228
if not self.wait_status.wait(DEFAULT_CONNECTION_TIMEOUT):
229-
raise Exception("Action client failed to connect, no status received.")
229+
raise TimeoutError("Action client failed to connect, no status received.")
230230

231231
def _on_status_message(self, message):
232232
self.wait_status.set()

src/roslibpy/comm/comm_autobahn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def raise_timeout_exception(self, _result=None, _timeout=None):
232232
Raises:
233233
An exception.
234234
"""
235-
raise Exception("No service response received")
235+
raise TimeoutError("No service response received")
236236

237237
def get_inner_callback(self, result_placeholder):
238238
"""Get the callback which, when called, provides result_placeholder with the result.

src/roslibpy/comm/comm_cli.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ def receive_chunk_async(self, task, context):
126126
context['buffer']), self.factory.manager.cancellation_token)
127127
receive_task.ContinueWith.Overloads[Action[Task[WebSocketReceiveResult], object], object](
128128
self.receive_chunk_async, context)
129-
except Exception:
129+
except Exception as exception:
130130
error_message = 'Exception on receive_chunk_async, processing will be aborted'
131131
if task:
132132
error_message += '; Task status: {}, Inner exception: {}'.format(task.Status, task.Exception)
133133
LOGGER.exception(error_message)
134-
raise
134+
raise RosBridgeException(error_message) from exception
135135

136136
def start_listening(self):
137137
"""Starts listening asynchronously while the socket is open.
@@ -164,10 +164,10 @@ def start_listening(self):
164164
except Exception:
165165
LOGGER.exception('Exception on start_listening while trying to handle message received.' +
166166
'It could indicate a bug in user code on message handlers. Message skipped.')
167-
except Exception:
168-
LOGGER.exception(
169-
'Exception on start_listening, processing will be aborted')
170-
raise
167+
except Exception as exception:
168+
error_message = 'Exception on start_listening, processing will be aborted'
169+
LOGGER.exception(error_message)
170+
raise RosBridgeException(error_message) from exception
171171
finally:
172172
LOGGER.debug('Leaving the listening thread')
173173

@@ -220,9 +220,10 @@ def send_chunk_async(self, task, message_data):
220220
task.ContinueWith(lambda _res: self.semaphore.Release())
221221

222222
return task
223-
except Exception:
224-
LOGGER.exception('Exception while on send_chunk_async')
225-
raise
223+
except Exception as exception:
224+
error_message = 'Exception while on send_chunk_async'
225+
LOGGER.exception(error_message)
226+
raise RosBridgeException(error_message) from exception
226227

227228
def send_message(self, payload):
228229
"""Start sending a message over the websocket asynchronously."""
@@ -240,9 +241,10 @@ def send_message(self, payload):
240241
None, [message_buffer, message_length, chunks_count, 0])
241242

242243
return send_task
243-
except Exception:
244-
LOGGER.exception('Exception while sending message')
245-
raise
244+
except Exception as exception:
245+
error_message = 'Exception while sending message'
246+
LOGGER.exception(error_message)
247+
raise RosBridgeException(error_message) from exception
246248

247249
def dispose(self, *args):
248250
"""Dispose the resources held by this protocol instance, i.e. socket."""
@@ -484,7 +486,7 @@ def raise_timeout_exception(self, _result=None, _timeout=None):
484486
Raises:
485487
An exception.
486488
"""
487-
raise Exception('No service response received')
489+
raise TimeoutError('No service response received')
488490

489491
def get_inner_callback(self, result_placeholder):
490492
"""Get the callback which, when called, provides result_placeholder with the result.

src/roslibpy/core.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,12 @@ def unadvertise(self):
310310
self._advertise_id = None
311311

312312

313+
class ServiceException(Exception):
314+
"""Exception that is thrown when a service call fails."""
315+
316+
pass
317+
318+
313319
class Service(object):
314320
"""Client/server of ROS services.
315321
@@ -382,7 +388,7 @@ def call(self, request, callback=None, errback=None, timeout=None):
382388
# Blocking mode
383389
call_results = self.ros.call_sync_service(message, timeout)
384390
if "exception" in call_results:
385-
raise Exception(call_results["exception"])
391+
raise ServiceException(call_results["exception"])
386392

387393
return call_results["result"]
388394

src/roslibpy/ros.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def run(self, timeout=CONNECTION_TIMEOUT):
9696
self.factory.on_ready(lambda _: wait_connect.set())
9797

9898
if not wait_connect.wait(timeout):
99-
raise Exception("Failed to connect to ROS")
99+
raise TimeoutError("Failed to connect to ROS")
100100

101101
def run_forever(self):
102102
"""Kick-starts a blocking loop to wait for events.

0 commit comments

Comments
 (0)