Skip to content

Commit c7bf3fa

Browse files
committed
Allow an empty or mal-formed config to be passed to the config system
1 parent 22acfbf commit c7bf3fa

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

tools/config.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
limitations under the License.
1616
"""
1717

18+
import os
19+
import sys
20+
1821
# Implementation of mbed configuration mechanism
1922
from tools.utils import json_file_to_dict
2023
from tools.targets import Target
21-
import os
2224

2325
# Base class for all configuration exceptions
2426
class ConfigException(Exception):
@@ -376,8 +378,12 @@ def __init__(self, target, top_level_dirs=None):
376378
app_config_location, full_path))
377379
else:
378380
app_config_location = full_path
379-
self.app_config_data = json_file_to_dict(app_config_location) \
380-
if app_config_location else {}
381+
try:
382+
self.app_config_data = json_file_to_dict(app_config_location) \
383+
if app_config_location else {}
384+
except ValueError as exc:
385+
sys.stderr.write(str(exc) + "\n")
386+
self.app_config_data = {}
381387
# Check the keys in the application configuration data
382388
unknown_keys = set(self.app_config_data.keys()) - \
383389
self.__allowed_keys["application"]
@@ -419,7 +425,12 @@ def add_config_files(self, flist):
419425
self.processed_configs[full_path] = True
420426
# Read the library configuration and add a "__full_config_path"
421427
# attribute to it
422-
cfg = json_file_to_dict(config_file)
428+
try:
429+
cfg = json_file_to_dict(config_file)
430+
except ValueError as exc:
431+
sys.stderr.write(str(exc) + "\n")
432+
continue
433+
423434
cfg["__config_path"] = full_path
424435

425436
if "name" not in cfg:

0 commit comments

Comments
 (0)