From 98610746c8f32dfa2680f0e361c418ff03ad3459 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Wed, 17 Aug 2022 22:00:51 +0200 Subject: [PATCH] Improve config file setup and error handling. --- pyproject.toml | 2 +- src/antsibull/cli/antsibull_build.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 38dde237..ee91d4b2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,7 +35,7 @@ antsibull-lint = "antsibull.cli.antsibull_lint:main" [tool.poetry.dependencies] python = "^3.6.1" antsibull-changelog = ">= 0.14.0" -antsibull-core = ">= 1.0.0, < 2.0.0" +antsibull-core = ">= 1.2.0, < 2.0.0" antsibull-docs = ">= 1.0.0, < 2.0.0" asyncio-pool = "*" jinja2 = "*" diff --git a/src/antsibull/cli/antsibull_build.py b/src/antsibull/cli/antsibull_build.py index 1d680d61..c81726a0 100644 --- a/src/antsibull/cli/antsibull_build.py +++ b/src/antsibull/cli/antsibull_build.py @@ -23,7 +23,7 @@ from antsibull_core.args import ( # noqa: E402 InvalidArgumentError, get_toplevel_parser, normalize_toplevel_options ) -from antsibull_core.config import load_config # noqa: E402 +from antsibull_core.config import ConfigError, load_config # noqa: E402 from ..build_collection import build_collection_command # noqa: E402 from ..build_ansible_commands import ( # noqa: E402 @@ -384,14 +384,19 @@ def run(args: List[str]) -> int: print(e) return 2 - cfg = load_config(parsed_args.config_file) - flog.fields(config=cfg).info('Config loaded') + try: + cfg = load_config(parsed_args.config_file) + flog.fields(config=cfg).info('Config loaded') + except ConfigError as e: + print(e) + return 2 context_data = app_context.create_contexts(args=parsed_args, cfg=cfg) with app_context.app_and_lib_context(context_data) as (app_ctx, dummy_): twiggy.dict_config(app_ctx.logging_cfg.dict()) flog.debug('Set logging config') + flog.fields(command=parsed_args.command).info('Action') return ARGS_MAP[parsed_args.command]()