conf: log clearer and less verbose error on validation failure

This commit is contained in:
Fabio Valentini 2023-10-10 02:22:32 +02:00
parent 8506b843c5
commit 0034c349f2
No known key found for this signature in database
GPG key ID: 5AC5F572E5D410AF

View file

@ -526,7 +526,22 @@ def load_config(features: set[str], target: str) -> TomlConf:
except FileNotFoundError as exc:
tomlconf = None
except (ConfError, jsonschema.ValidationError) as exc:
except jsonschema.ValidationError as exc:
if not exc.path:
log.error("Invalid rust2rpm.toml file (unknown setting or table):")
log.error(exc.message)
else:
err_path = ""
for elem in exc.path:
if isinstance(elem, int):
err_path += f"[{elem}]"
else:
err_path += f"/{elem}"
log.error(f"Invalid rust2rpm.toml file (invalid setting at {err_path!r}):")
log.error(exc.message)
sys.exit(1)
except ConfError as exc:
log.error("Invalid rust2rpm.toml file:")
log.error(str(exc))
sys.exit(1)