From f1a8c865a6f74d7aab5b490dcb38aac62ea5a5d7 Mon Sep 17 00:00:00 2001 From: Alejandro Villar Date: Mon, 16 Sep 2024 13:38:39 +0200 Subject: [PATCH] Improve error reporting and fail on errors by default --- ogc/bblocks/entrypoint.py | 2 +- ogc/bblocks/postprocess.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ogc/bblocks/entrypoint.py b/ogc/bblocks/entrypoint.py index e92cdec..ce66233 100644 --- a/ogc/bblocks/entrypoint.py +++ b/ogc/bblocks/entrypoint.py @@ -50,7 +50,7 @@ parser.add_argument( '--fail-on-error', - default='false', + default='true', help='Fail run if an error is encountered', ) diff --git a/ogc/bblocks/postprocess.py b/ogc/bblocks/postprocess.py index 4917c4d..885fcc0 100644 --- a/ogc/bblocks/postprocess.py +++ b/ogc/bblocks/postprocess.py @@ -12,6 +12,7 @@ import traceback from urllib.parse import urljoin +from ogc.na.exceptions import ContextLoadError from ogc.na.util import is_url, dump_yaml from ogc.bblocks.generate_docs import DocGenerator @@ -280,6 +281,11 @@ def do_postprocess(bblock: BuildingBlock, light: bool = False) -> bool: if fail_on_error: raise traceback.print_exception(e, file=sys.stderr) + if isinstance(e, ContextLoadError): + if e.__cause__: + print(f"{e}: {e.__cause__}", file=sys.stderr) + else: + print(str(e), file=sys.stderr) if building_block.openapi.exists: print(f"Annotating OpenAPI document for {building_block.identifier}", file=sys.stderr)