From 477b947b22898838cbdad2202d7dcfb689253e9b Mon Sep 17 00:00:00 2001 From: Jimmy Brisson Date: Wed, 28 Feb 2018 13:59:57 -0600 Subject: [PATCH] Improve json schema validation errors --- tools/config/__init__.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tools/config/__init__.py b/tools/config/__init__.py index 0bbafa81e5..7bdbd41238 100644 --- a/tools/config/__init__.py +++ b/tools/config/__init__.py @@ -384,6 +384,13 @@ class Config(object): app_config_location = full_path return app_config_location + def format_validation_error(self, error, path): + if error.context: + return self.format_validation_error(error.context[0], path) + else: + return "in {} element {}: {}".format( + path, str(".".join(error.absolute_path)), error.message) + def __init__(self, tgt, top_level_dirs=None, app_config=None): """Construct a mbed configuration @@ -430,7 +437,9 @@ class Config(object): errors = sorted(validator.iter_errors(self.app_config_data)) if errors: - raise ConfigException(",".join(x.message for x in errors)) + raise ConfigException("; ".join( + self.format_validation_error(x, self.app_config_location) + for x in errors)) # Update the list of targets with the ones defined in the application # config, if applicable @@ -494,7 +503,9 @@ class Config(object): errors = sorted(validator.iter_errors(cfg)) if errors: - raise ConfigException(",".join(x.message for x in errors)) + raise ConfigException("; ".join( + self.format_validation_error(x, config_file) + for x in errors)) cfg["__config_path"] = full_path