Clearer error when getting non-existing slot
This commit is contained in:
parent
67c6779b20
commit
7338a6675d
1 changed files with 9 additions and 2 deletions
11
api/od.py
11
api/od.py
|
|
@ -56,7 +56,10 @@ class ODAPI:
|
||||||
return self.bottom.read_edge_source(link)
|
return self.bottom.read_edge_source(link)
|
||||||
|
|
||||||
def get_slot(self, obj: UUID, attr_name: str):
|
def get_slot(self, obj: UUID, attr_name: str):
|
||||||
return self.od.get_slot(obj, attr_name)
|
slot = self.od.get_slot(obj, attr_name)
|
||||||
|
if slot == None:
|
||||||
|
raise Exception(f"Object '{self.obj_to_name[obj]}' has no slot '{attr_name}'")
|
||||||
|
return slot
|
||||||
|
|
||||||
def get_slot_link(self, obj: UUID, attr_name: str):
|
def get_slot_link(self, obj: UUID, attr_name: str):
|
||||||
return self.od.get_slot_link(obj, attr_name)
|
return self.od.get_slot_link(obj, attr_name)
|
||||||
|
|
@ -109,6 +112,7 @@ class ODAPI:
|
||||||
def get_slot_value(self, obj: UUID, attr_name: str):
|
def get_slot_value(self, obj: UUID, attr_name: str):
|
||||||
return self.get_value(self.get_slot(obj, attr_name))
|
return self.get_value(self.get_slot(obj, attr_name))
|
||||||
|
|
||||||
|
# create or update slot value
|
||||||
def set_slot_value(self, obj: UUID, attr_name: str, new_value: any):
|
def set_slot_value(self, obj: UUID, attr_name: str, new_value: any):
|
||||||
obj_name = self.get_name(obj)
|
obj_name = self.get_name(obj)
|
||||||
|
|
||||||
|
|
@ -149,4 +153,7 @@ class ODAPI:
|
||||||
NEXT_ID += 1
|
NEXT_ID += 1
|
||||||
link_id = self.od._create_link(link_name, typ, src, tgt)
|
link_id = self.od._create_link(link_name, typ, src, tgt)
|
||||||
self.__recompute_mappings()
|
self.__recompute_mappings()
|
||||||
return link_id
|
return link_id
|
||||||
|
|
||||||
|
def create_object(self, object_name: Optional[str], class_name: str):
|
||||||
|
return self.od.create_object(object_name, class_name)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue