Skip to content

Commit 7cfa7bc

Browse files
author
Michael Fritzsche
committed
made process step and ld_container._to_expanded_json more robust
1 parent d4d9ca8 commit 7cfa7bc

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

src/hermes/commands/process/base.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from hermes.commands.base import HermesCommand, HermesPlugin
1212
from hermes.model.api import SoftwareMetadata
1313
from hermes.model.context_manager import HermesContext
14+
from hermes.model.error import HermesContextError
1415
from hermes.model.merge.container import ld_merge_dict
1516

1617

@@ -42,7 +43,13 @@ def __call__(self, args: argparse.Namespace) -> None:
4243
ctx.prepare_step('harvest')
4344
for harvester in harvester_names:
4445
self.log.info("## Process data from %s", harvester)
45-
merged_doc.update(SoftwareMetadata.load_from_cache(ctx, harvester))
46+
try:
47+
metadata = SoftwareMetadata.load_from_cache(ctx, harvester)
48+
except HermesContextError as e:
49+
self.log.error("Error while trying to load data from harvest plugin '%s': %s", harvester, e)
50+
self.errors.append(e)
51+
continue
52+
merged_doc.update(metadata)
4653
ctx.finalize_step("harvest")
4754

4855
ctx.prepare_step("process")

src/hermes/model/types/ld_container.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def _to_expanded_json(
237237
# while searching build a path such that it leads from the found ld_dicts ld_value to selfs data_dict/ item_list
238238
parent = self
239239
path = []
240-
while parent.__class__.__name__ not in ("ld_dict", "SoftwareMetadata", "ld_merge_dict"):
240+
while not "ld_dict" in [sub_cls.__name__ for sub_cls in type(parent).mro()]:
241241
if parent.container_type == "@list":
242242
path.extend(["@list", 0])
243243
elif parent.container_type == "@graph":
@@ -250,7 +250,7 @@ def _to_expanded_json(
250250
# if neither self nor any of its parents is a ld_dict:
251251
# create a dict with the key of the outer most parent of self and this parents ld_value as a value
252252
# this dict is stored in an ld_container and simulates the most minimal JSON-LD object possible
253-
if parent.__class__.__name__ not in ("ld_dict", "SoftwareMetadata", "ld_merge_dict"):
253+
if not "ld_dict" in [sub_cls.__name__ for sub_cls in type(parent).mro()]:
254254
key = self.ld_proc.expand_iri(parent.active_ctx, parent.key)
255255
parent = ld_container([{key: parent._data}])
256256
path.append(0)
@@ -277,7 +277,7 @@ def _to_expanded_json(
277277
[(new_key, temp) for new_key in temp.keys() if isinstance(temp[new_key], special_types)]
278278
)
279279
elif isinstance(temp, ld_container):
280-
if temp.__class__.__name__ in ("ld_list", "ld_merge_list") and temp.container_type == "@set":
280+
if "ld_list" in [sub_cls.__name__ for sub_cls in type(temp).mro()] and temp.container_type == "@set":
281281
ref[key] = temp._data
282282
else:
283283
ref[key] = temp._data[0]

0 commit comments

Comments
 (0)