diff --git a/platformio/exception.py b/platformio/exception.py index 8b3df0f2..ec0737de 100644 --- a/platformio/exception.py +++ b/platformio/exception.py @@ -192,6 +192,11 @@ class InvalidLibConfURL(PlatformioException): MESSAGE = "Invalid library config URL '{0}'" +class InvalidProjectConf(PlatformioException): + + MESSAGE = "Invalid `platformio.ini`, project configuration file: '{0}'" + + class BuildScriptNotFound(PlatformioException): MESSAGE = "Invalid path '{0}' to build script" diff --git a/platformio/util.py b/platformio/util.py index e37660e2..98c3cbc1 100644 --- a/platformio/util.py +++ b/platformio/util.py @@ -36,23 +36,27 @@ from platformio import __apiurl__, __version__, exception # pylint: disable=wrong-import-order, too-many-ancestors try: - from configparser import ConfigParser + import configparser as ConfigParser except ImportError: - from ConfigParser import ConfigParser + import ConfigParser as ConfigParser -class ProjectConfig(ConfigParser): +class ProjectConfig(ConfigParser.ConfigParser): VARTPL_RE = re.compile(r"\$\{([^\.\}]+)\.([^\}]+)\}") def items(self, section, **_): # pylint: disable=arguments-differ items = [] - for option in ConfigParser.options(self, section): + for option in ConfigParser.ConfigParser.options(self, section): items.append((option, self.get(section, option))) return items def get(self, section, option, **kwargs): - value = ConfigParser.get(self, section, option, **kwargs) + try: + value = ConfigParser.ConfigParser.get(self, section, option, + **kwargs) + except ConfigParser.Error as e: + raise exception.InvalidProjectConf(str(e)) if "${" not in value or "}" not in value: return value return self.VARTPL_RE.sub(self._re_sub_handler, value) @@ -331,7 +335,10 @@ def load_project_config(path=None): raise exception.NotPlatformIOProject( dirname(path) if path.endswith("platformio.ini") else path) cp = ProjectConfig() - cp.read(path) + try: + cp.read(path) + except ConfigParser.Error as e: + raise exception.InvalidProjectConf(str(e)) return cp