Skip to content

Commit

Permalink
Improve try-catch for main loop
Browse files Browse the repository at this point in the history
  • Loading branch information
avillar committed Jul 3, 2024
1 parent f893258 commit f05639a
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions ogc/bblocks/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,13 @@ def do_postprocess(bblock: BuildingBlock, light: bool = False) -> bool:

if building_block.openapi.exists:
print(f"Annotating OpenAPI document for {building_block.identifier}", file=sys.stderr)
openapi_resolved = resolve_all_schema_references(building_block.openapi.load_yaml(), bbr,
building_block, building_block.openapi, base_url)
building_block.output_openapi.parent.mkdir(parents=True, exist_ok=True)
dump_yaml(openapi_resolved, building_block.output_openapi)
print(f" - {os.path.relpath(building_block.output_openapi)}", file=sys.stderr)

try:
openapi_resolved = resolve_all_schema_references(building_block.openapi.load_yaml(), bbr,
building_block, building_block.openapi, base_url)
building_block.output_openapi.parent.mkdir(parents=True, exist_ok=True)
dump_yaml(openapi_resolved, building_block.output_openapi)
print(f" - {os.path.relpath(building_block.output_openapi)}", file=sys.stderr)

if openapi_resolved.get('openapi', '').startswith('3.1'):
print(f"Downcompiling OpenAPI document to 3.0 for {building_block.identifier}", file=sys.stderr)
oas30_doc_fn = building_block.output_openapi_30
Expand All @@ -290,22 +290,22 @@ def do_postprocess(bblock: BuildingBlock, light: bool = False) -> bool:

if building_block.ontology.exists:
building_block.metadata.pop('ontology', None)
if building_block.ontology.is_path and building_block.ontology_graph:
try:
try:
if building_block.ontology.is_path and building_block.ontology_graph:
building_block.output_ontology.parent.mkdir(parents=True, exist_ok=True)
building_block.ontology_graph.serialize(building_block.output_ontology, 'ttl')
building_block.metadata['ontology'] = PathOrUrl(building_block.output_ontology)\
.with_base_url(base_url)
except Exception as e:
if fail_on_error:
raise BuildingBlockError(f'Error processing ontology for {building_block.identifier}')\
from e
print("Exception when processing ontology for", building_block.identifier, file=sys.stderr)
traceback.print_exception(e, file=sys.stderr)
elif building_block.ontology.is_url:
# Force cache
building_block.ontology_graph
building_block.metadata['ontology'] = building_block.ontology.value
elif building_block.ontology.is_url:
# Force cache
building_block.ontology_graph
building_block.metadata['ontology'] = building_block.ontology.value
except Exception as e:
if fail_on_error:
raise BuildingBlockError(f'Error processing ontology for {building_block.identifier}')\
from e
print("Exception when processing ontology for", building_block.identifier, file=sys.stderr)
traceback.print_exception(e, file=sys.stderr)

if base_url and building_block.remote_cache_dir.is_dir():
building_block.metadata['remoteCacheDir'] = (
Expand Down

0 comments on commit f05639a

Please sign in to comment.