Skip to content

Commit

Permalink
control/state.py: catch concrete exceptions
Browse files Browse the repository at this point in the history
catching a concrete exception rather than a generic Exception for precise error handling, to avoid masking unrelated issues, and ito improve code readability and debugging.

Signed-off-by: Alexander Indenbaum <[email protected]>
  • Loading branch information
Alexander Indenbaum authored and baum committed Nov 13, 2024
1 parent 6ac0a55 commit 5a51c87
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions control/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,12 +744,12 @@ def namespace_only_lb_group_id_changed(self, old_val, new_val):
new_req = None
try:
old_req = json_format.Parse(old_val, pb2.namespace_add_req(), ignore_unknown_fields=True)
except Exception as ex:
except json_format.ParseError:
self.logger.exception(f"Got exception parsing {old_val}")
return (False, None)
try:
new_req = json_format.Parse(new_val, pb2.namespace_add_req(), ignore_unknown_fields=True)
except Exception as ex:
except json_format.ParseError:
self.logger.exeption(f"Got exception parsing {new_val}")
return (False, None)
if not old_req or not new_req:
Expand All @@ -768,12 +768,12 @@ def host_only_key_changed(self, old_val, new_val):
new_req = None
try:
old_req = json_format.Parse(old_val, pb2.add_host_req(), ignore_unknown_fields=True )
except Exception as ex:
except json_format.ParseError:
self.logger.exception(f"Got exception parsing {old_val}")
return (False, None)
try:
new_req = json_format.Parse(new_val, pb2.add_host_req(), ignore_unknown_fields=True)
except Exception as ex:
except json_format.ParseError:
self.logger.exeption(f"Got exception parsing {new_val}")
return (False, None)
if not old_req or not new_req:
Expand All @@ -797,12 +797,12 @@ def subsystem_only_key_changed(self, old_val, new_val):
new_req = None
try:
old_req = json_format.Parse(old_val, pb2.create_subsystem_req(), ignore_unknown_fields=True )
except Exception as ex:
except json_format.ParseError:
self.logger.exception(f"Got exception parsing {old_val}")
return (False, None)
try:
new_req = json_format.Parse(new_val, pb2.create_subsystem_req(), ignore_unknown_fields=True)
except Exception as ex:
except json_format.ParseError:
self.logger.exeption(f"Got exception parsing {new_val}")
return (False, None)
if not old_req or not new_req:
Expand Down Expand Up @@ -835,8 +835,8 @@ def break_namespace_key(self, ns_key: str):
nqn = key_parts[0]
try:
nsid = int(key_parts[1])
except Exception as ex:
self.logger.warning(f"Invalid NSID \"{key_parts[1]}\" found for namespace key \"{ns_key}\", can't find key parts")
except ValueError:
self.logger.exception(f"Invalid NSID \"{key_parts[1]}\" found for namespace key \"{ns_key}\", can't find key parts")
return (None, None)

return (nqn, nsid)
Expand Down

0 comments on commit 5a51c87

Please sign in to comment.