From c7bf3fac60542eb5b85c8d9d0ab51d5652e5cbf5 Mon Sep 17 00:00:00 2001 From: Jimmy Brisson Date: Mon, 29 Aug 2016 09:54:56 -0500 Subject: [PATCH] Allow an empty or mal-formed config to be passed to the config system --- tools/config.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tools/config.py b/tools/config.py index e6f8c638629..a4766b3e2db 100644 --- a/tools/config.py +++ b/tools/config.py @@ -15,10 +15,12 @@ limitations under the License. """ +import os +import sys + # Implementation of mbed configuration mechanism from tools.utils import json_file_to_dict from tools.targets import Target -import os # Base class for all configuration exceptions class ConfigException(Exception): @@ -376,8 +378,12 @@ def __init__(self, target, top_level_dirs=None): app_config_location, full_path)) else: app_config_location = full_path - self.app_config_data = json_file_to_dict(app_config_location) \ - if app_config_location else {} + try: + self.app_config_data = json_file_to_dict(app_config_location) \ + if app_config_location else {} + except ValueError as exc: + sys.stderr.write(str(exc) + "\n") + self.app_config_data = {} # Check the keys in the application configuration data unknown_keys = set(self.app_config_data.keys()) - \ self.__allowed_keys["application"] @@ -419,7 +425,12 @@ def add_config_files(self, flist): self.processed_configs[full_path] = True # Read the library configuration and add a "__full_config_path" # attribute to it - cfg = json_file_to_dict(config_file) + try: + cfg = json_file_to_dict(config_file) + except ValueError as exc: + sys.stderr.write(str(exc) + "\n") + continue + cfg["__config_path"] = full_path if "name" not in cfg: