Skip to content

Commit 477b947

Browse files
committed
Improve json schema validation errors
1 parent 3d1174a commit 477b947

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

tools/config/__init__.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,13 @@ def find_app_config(cls, top_level_dirs):
384384
app_config_location = full_path
385385
return app_config_location
386386

387+
def format_validation_error(self, error, path):
388+
if error.context:
389+
return self.format_validation_error(error.context[0], path)
390+
else:
391+
return "in {} element {}: {}".format(
392+
path, str(".".join(error.absolute_path)), error.message)
393+
387394
def __init__(self, tgt, top_level_dirs=None, app_config=None):
388395
"""Construct a mbed configuration
389396
@@ -430,7 +437,9 @@ def __init__(self, tgt, top_level_dirs=None, app_config=None):
430437
errors = sorted(validator.iter_errors(self.app_config_data))
431438

432439
if errors:
433-
raise ConfigException(",".join(x.message for x in errors))
440+
raise ConfigException("; ".join(
441+
self.format_validation_error(x, self.app_config_location)
442+
for x in errors))
434443

435444
# Update the list of targets with the ones defined in the application
436445
# config, if applicable
@@ -494,7 +503,9 @@ def add_config_files(self, flist):
494503
errors = sorted(validator.iter_errors(cfg))
495504

496505
if errors:
497-
raise ConfigException(",".join(x.message for x in errors))
506+
raise ConfigException("; ".join(
507+
self.format_validation_error(x, config_file)
508+
for x in errors))
498509

499510
cfg["__config_path"] = full_path
500511

0 commit comments

Comments
 (0)