Skip to content

Commit

Permalink
schema: make validation error message less verbose
Browse files Browse the repository at this point in the history
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 <felix.moessbauer@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
  • Loading branch information
fmoessbauer authored and jan-kiszka committed Jan 30, 2025
1 parent d1c28fa commit a4792e2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions kas/includehandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit a4792e2

Please # to comment.