Skip to content

Commit

Permalink
Fix bare exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
cclauss committed Aug 20, 2021
1 parent a5e8889 commit 8aa8649
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 21 deletions.
6 changes: 3 additions & 3 deletions rosapi/src/rosapi/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def _set_param(node_name, name, value, parameter_type=None):
try:
# call_get_parameters will fail if node does not exist.
call_set_parameters(node=_node, node_name=node_name, parameters=[parameter])
except:
except Exception:
pass


Expand Down Expand Up @@ -138,7 +138,7 @@ def get_param(node_name, name, default, params_glob):
# if type is 0 (parameter not set), the next line will raise an exception
# and return value shall go to default.
value = getattr(pvalue, _parameter_type_mapping[pvalue.type])
except:
except Exception:
# If either the node or the parameter does not exist, return default.
value = default

Expand All @@ -160,7 +160,7 @@ def has_param(node_name, name, params_glob):
response = call_get_parameters(
node=_node, node_name=node_name,
parameter_names=[name])
except:
except Exception:
return False

return response.values[0].type > 0 and response.values[0].type < len(_parameter_type_mapping)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,16 +242,10 @@ def _to_inst(msg, rostype, roottype, inst=None, stack=[]):


def _to_binary_inst(msg):
if type(msg) in string_types:
try:
return standard_b64decode(msg)
except :
return msg
else:
try:
return bytes(bytearray(msg))
except:
return msg
try:
return standard_b64decode(msg) if isinstance(msg, str) else bytes(bytearray(msg))
except Exception:
return msg


def _to_time_inst(msg, rostype, inst=None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ def run(self):
if self.alive and self.time_remaining() == 0 and len(self.queue) > 0:
try:
MessageHandler.handle_message(self, self.queue[0])
except:
except Exception:
pass
del self.queue[0]
while self.time_remaining() == 0 and len(self.queue) > 0:
try:
MessageHandler.handle_message(self, self.queue[0])
except:
except Exception:
pass
del self.queue[0]
2 changes: 1 addition & 1 deletion rosbridge_library/src/rosbridge_library/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def serialize(self, msg, cid=None):
return bson.BSON.encode(msg)
else:
return json.dumps(msg)
except:
except Exception:
if cid is not None:
# Only bother sending the log message if there's an id
self.log("error", "Unable to serialize %s message to client"
Expand Down
2 changes: 1 addition & 1 deletion rosbridge_library/test/capabilities/test_subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_update_params(self):
self.assertEqual(subscription.queue_length, min_queue_length)
self.assertEqual(subscription.fragment_size, min_frag_size)
self.assertEqual(subscription.compression, "png")
except:
except: # noqa: E722 # Will unregister and raise
subscription.unregister()
raise

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def cb(msg):

try:
self.assertEqual(["hello"] + list(range(990, 1000)), received["msgs"])
except:
except: # noqa: E722 # Will finish and raise
handler.finish()
raise

Expand Down Expand Up @@ -207,7 +207,7 @@ def cb(msg):
for x in range(10):
self.assertEqual(x, received["msg"])
time.sleep(throttle_rate_sec)
except:
except: # noqa: E722 # Will finish and raise
handler.finish()
raise

Expand Down
2 changes: 1 addition & 1 deletion rosbridge_library/test/internal/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def callback(self, req):
gen = populate_random_args(gen)
try:
rsp = c.populate_instance(gen, rsp)
except:
except: # noqa: E722 # Will print() and raise
print("populating instance")
print(rsp)
print("populating with")
Expand Down
2 changes: 1 addition & 1 deletion rosbridge_server/src/rosbridge_server/websocket_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def prewrite_message(self, message, binary):
else:
_log_exception()
raise
except:
except: # noqa: E722 # Will log and raise
_log_exception()
raise

Expand Down

0 comments on commit 8aa8649

Please sign in to comment.