From a4792e23ebd76756238e425cd7266ece7b11a590 Mon Sep 17 00:00:00 2001 From: Felix Moessbauer Date: Thu, 30 Jan 2025 11:37:00 +0100 Subject: [PATCH] schema: make validation error message less verbose In case the config does not validate against the schema a very long error message was printed which even included the schema definition itself (per single error). This has proven to be not very helpful, as it made the actual error hard to spot. We change this by following the upstream recommendation of sorting the errors and also only printing the error message (which only contains the affected node), reducing the error message from >300 to a couple of lines. When running in debug mode, we explicitly dump the schema on error, but only once for all errors. Signed-off-by: Felix Moessbauer Signed-off-by: Jan Kiszka --- kas/includehandler.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kas/includehandler.py b/kas/includehandler.py index 2aeaacff..c2b56a8a 100644 --- a/kas/includehandler.py +++ b/kas/includehandler.py @@ -75,11 +75,13 @@ def load_config(filename): validator = validator_class(CONFIGSCHEMA) validation_error = False - for error in validator.iter_errors(config): + for error in sorted(validator.iter_errors(config), key=str): validation_error = True - logging.error('Config file validation Error:\n%s', error) + logging.error('Config file validation Error:\n%s', error.message) if validation_error: + logging.debug('Validation against this schema failed:\n%s', + json.dumps(error.schema, indent=2)) raise LoadConfigException('Error(s) occured while validating the ' 'config file', filename)