@@ -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.
0 commit comments