Skip to content

Commit

Permalink
try custom errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gtfierro committed Nov 20, 2024
1 parent 644827e commit 4be13ca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
17 changes: 12 additions & 5 deletions buildingmotif/database/table_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
DBTemplate,
DepsAssociation,
)
from buildingmotif.database.errors import LibraryNotFound, TemplateNotFound


class TableConnection:
Expand Down Expand Up @@ -216,7 +217,10 @@ def get_db_library(self, id: int) -> DBLibrary:
:return: DBLibrary
:rtype: DBLibrary
"""
db_library = self.bm.session.query(DBLibrary).filter(DBLibrary.id == id).one()
try:
db_library = self.bm.session.query(DBLibrary).filter(DBLibrary.id == id).one()
except NoResultFound:
raise LibraryNotFound(f"Library with id {id} not found")
return db_library

def get_db_library_by_name(self, name: str) -> DBLibrary:
Expand Down Expand Up @@ -298,9 +302,12 @@ def get_db_template(self, id: int) -> DBTemplate:
:return: DBTemplate
:rtype: DBTemplate
"""
db_template = (
self.bm.session.query(DBTemplate).filter(DBTemplate.id == id).one()
)
try:
db_template = (
self.bm.session.query(DBTemplate).filter(DBTemplate.id == id).one()
)
except NoResultFound:
raise TemplateNotFound(idnum=id)
return db_template

def get_db_template_by_name(self, name: str) -> DBTemplate:
Expand All @@ -316,7 +323,7 @@ def get_db_template_by_name(self, name: str) -> DBTemplate:
self.bm.session.query(DBTemplate).filter(DBTemplate.name == name).one()
)
except NoResultFound:
raise NoResultFound(f"No template found with name {name}")
raise TemplateNotFound(name=name)
return db_template

def get_library_defining_db_template(self, id: int) -> DBLibrary:
Expand Down
1 change: 0 additions & 1 deletion buildingmotif/dataclasses/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ def _infer_templates_from_graph(self, graph: rdflib.Graph):
logging.warning(
f"An ontology could not resolve a dependency on {dependency} ({e}). Check this is loaded into BuildingMOTIF"
)
get_building_motif().session.rollback()
continue
class_candidates = set(graph.subjects(rdflib.RDF.type, rdflib.OWL.Class))
shape_candidates = set(graph.subjects(rdflib.RDF.type, rdflib.SH.NodeShape))
Expand Down

0 comments on commit 4be13ca

Please sign in to comment.