Changes try-except-blocks around maybe_nody_by_*() calls to only catch KeyError exceptions.
Semantically, all the implemented error handling for the try-except- blocks around calls to "maybe_node_by_mac()" or "maybe_node_by_id()" in nodedb.py only handle the case that a particular MAC address cannot be found in the list of known nodes. If such a MAC address cannot be found in this list, the methods properly indicate this by raising a KeyError. However, all the try-except-block generically catch all exceptions and thus may cover other problems. But not only that problems might be covered by this, generic try-except-blocks make finding errors and de- bugging quite painful. Hence, these try-except-blocks should only catch KeyErrors or at least have an error handling that differs from other exceptions.
This commit is contained in:
parent
94f7256564
commit
b3c629264a
18
nodedb.py
18
nodedb.py
|
@ -46,7 +46,7 @@ class NodeDB:
|
|||
for n in obj:
|
||||
try:
|
||||
node = self.maybe_node_by_id(n['id'])
|
||||
except:
|
||||
except KeyError:
|
||||
node = Node()
|
||||
node.id = n['id']
|
||||
node.name = n['name']
|
||||
|
@ -81,7 +81,7 @@ class NodeDB:
|
|||
if 'of' in x:
|
||||
try:
|
||||
node = self.maybe_node_by_mac((x['of'], x['secondary']))
|
||||
except:
|
||||
except KeyError:
|
||||
node = Node()
|
||||
node.lastseen = self.time
|
||||
node.firstseen = self.time
|
||||
|
@ -99,7 +99,7 @@ class NodeDB:
|
|||
|
||||
try:
|
||||
node = self.maybe_node_by_mac((x['router'], ))
|
||||
except:
|
||||
except KeyError:
|
||||
node = Node()
|
||||
node.lastseen = self.time
|
||||
node.firstseen = self.time
|
||||
|
@ -111,14 +111,14 @@ class NodeDB:
|
|||
if 'neighbor' in x:
|
||||
try:
|
||||
node = self.maybe_node_by_mac((x['neighbor'], ))
|
||||
except:
|
||||
except KeyError:
|
||||
continue
|
||||
|
||||
if 'gateway' in x:
|
||||
x['neighbor'] = x['gateway']
|
||||
|
||||
node = self.maybe_node_by_mac((x['neighbor'], ))
|
||||
except:
|
||||
except KeyError:
|
||||
node = Node()
|
||||
node.lastseen = self.time
|
||||
node.firstseen = self.time
|
||||
|
@ -138,7 +138,7 @@ class NodeDB:
|
|||
|
||||
router = self.maybe_node_by_mac((x['router'], ))
|
||||
neighbor = self.maybe_node_by_mac((x['neighbor'], ))
|
||||
except:
|
||||
except KeyError:
|
||||
continue
|
||||
|
||||
# filter TT links merged in previous step
|
||||
|
@ -161,7 +161,7 @@ class NodeDB:
|
|||
if 'primary' in x:
|
||||
try:
|
||||
node = self.maybe_node_by_mac((x['primary'], ))
|
||||
except:
|
||||
except KeyError:
|
||||
continue
|
||||
|
||||
node.id = x['primary']
|
||||
|
@ -172,7 +172,7 @@ class NodeDB:
|
|||
node = self.maybe_node_by_mac((x['router'], ))
|
||||
node.add_mac(x['gateway'])
|
||||
node.clientcount += 1
|
||||
except:
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
# don't count node as its own client
|
||||
|
@ -207,7 +207,7 @@ class NodeDB:
|
|||
for mac, alias in aliases.items():
|
||||
try:
|
||||
node = self.maybe_node_by_mac([mac])
|
||||
except:
|
||||
except KeyError:
|
||||
# create an offline node
|
||||
node = Node()
|
||||
node.add_mac(mac)
|
||||
|
|
Loading…
Reference in a new issue