Skip to content

Commit c624798

Browse files
committed
Added error handling to cope with name/id not known
1 parent a1e971f commit c624798

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

feshiedb.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,11 @@ def get_node_name(self, node_id):
432432
self.db.query(
433433
"SELECT name FROM current_names WHERE device_id = \"%s\";"
434434
% node_id)
435-
raw = self.db.store_result().fetch_row(0)[0][0]
435+
try:
436+
raw = self.db.store_result().fetch_row(0)[0][0]
437+
except IndexError:
438+
#Means that there is no known name for this id
439+
raw = node_id
436440
return raw
437441

438442
def get_node_id(self, name):
@@ -441,7 +445,11 @@ def get_node_id(self, name):
441445
self.db.query(
442446
"SELECT device_id FROM current_names WHERE name = \"%s\";"
443447
% name)
444-
raw = self.db.store_result().fetch_row(0)[0][0]
448+
try:
449+
raw = self.db.store_result().fetch_row(0)[0][0]
450+
except IndexError:
451+
#Name not known therefore cannot tell what node it is meant to be
452+
raw = None
445453
return raw
446454

447455
class FeshieDbConfig(object):

0 commit comments

Comments
 (0)