Skip to content

Commit 0834bcc

Browse files
committed
Improve exceptions for dependency and YAML loading
1 parent 4914a93 commit 0834bcc

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

ogc/bblocks/models.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -497,18 +497,21 @@ def __init__(self,
497497
self.imported_bblock_files[d] = identifier
498498

499499
for bblock in self.bblocks.values():
500-
found_deps = self._resolve_bblock_deps(bblock)
501-
deps = bblock.metadata.get('dependsOn')
502-
if isinstance(deps, str):
503-
found_deps.add(deps)
504-
elif isinstance(deps, list):
505-
found_deps.update(deps)
506-
if found_deps:
507-
bblock.metadata['dependsOn'] = list(found_deps)
508-
dep_graph.add_node(bblock.identifier)
509-
dep_graph.add_edges_from([(d, bblock.identifier)
510-
for d in bblock.metadata.get('dependsOn', ())
511-
if d != bblock.identifier])
500+
try:
501+
found_deps = self._resolve_bblock_deps(bblock)
502+
deps = bblock.metadata.get('dependsOn')
503+
if isinstance(deps, str):
504+
found_deps.add(deps)
505+
elif isinstance(deps, list):
506+
found_deps.update(deps)
507+
if found_deps:
508+
bblock.metadata['dependsOn'] = list(found_deps)
509+
dep_graph.add_node(bblock.identifier)
510+
dep_graph.add_edges_from([(d, bblock.identifier)
511+
for d in bblock.metadata.get('dependsOn', ())
512+
if d != bblock.identifier])
513+
except Exception as e:
514+
raise Exception(f'Error resolving dependencies for {bblock.identifier}') from e
512515

513516
for a, b in dep_graph.edges:
514517
if a not in self.bblocks and a not in self.imported_bblocks:

ogc/bblocks/util.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,13 @@ def is_file(self):
166166

167167
@functools.cache
168168
def load_yaml(self):
169-
if self.is_url:
170-
return load_yaml(url=self.url)
171-
else:
172-
return load_yaml(filename=self.path)
169+
try:
170+
if self.is_url:
171+
return load_yaml(url=self.url)
172+
else:
173+
return load_yaml(filename=self.path)
174+
except Exception as e:
175+
raise IOError(f'Error loading YAML file from {self.url if self.is_url else self.path}') from e
173176

174177
@property
175178
def exists(self):

0 commit comments

Comments
 (0)