From 65b0321a8b92a4fcbb211caeec31aaa82a3a490c Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Thu, 21 Mar 2024 13:58:48 +0000 Subject: build script: T3664: fix handling of missing or malformed flavor files --- scripts/build-vyos-image | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/build-vyos-image b/scripts/build-vyos-image index fb7eb540..3d287406 100755 --- a/scripts/build-vyos-image +++ b/scripts/build-vyos-image @@ -193,9 +193,17 @@ if __name__ == "__main__": pre_build_config = merge_dicts({}, build_defaults) flavor_config = {} - with open(make_toml_path(defaults.BUILD_FLAVORS_DIR, args["build_flavor"]), 'rb') as f: - flavor_config = tomli.load(f) - pre_build_config = merge_dicts(flavor_config, pre_build_config) + build_flavor = args["build_flavor"] + try: + with open(make_toml_path(defaults.BUILD_FLAVORS_DIR, args["build_flavor"]), 'rb') as f: + flavor_config = tomli.load(f) + pre_build_config = merge_dicts(flavor_config, pre_build_config) + except FileNotFoundError: + print(f"E: Flavor '{build_flavor}' does not exist") + sys.exit(1) + except tomli.TOMLDecodeError as e: + print(f"E: Failed to parse TOML file for flavor '{build_flavor}': {e}") + sys.exit(1) ## Combine configs args > flavor > defaults pre_build_config = merge_dicts(args, pre_build_config, skip_none=True) -- cgit v1.2.3