From fb6dd955cbc7081f47dc43919075dc4eb3809172 Mon Sep 17 00:00:00 2001 From: Edward Cragg Date: Wed, 24 Feb 2016 18:06:07 +0000 Subject: Validate empty configure/build/test/install commands If a command in a chunk is evaluated to None when a morphology is loaded, this would previously lead to the subprocess module throwing a 'Coercing to Unicode' error when morph attempts to run the command during the chunk build. This change throws a more helpful error if any commands are not valid strings when the chunk is validated, for example: ERROR: Field configure-commands[217] expected type , got in morphology linux-jetson-tk1 Change-Id: I45220e7deab8c7cd9351507bc998f7ff12797442 --- morphlib/morphloader.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/morphlib/morphloader.py b/morphlib/morphloader.py index ff433d73..d7f0fe7e 100644 --- a/morphlib/morphloader.py +++ b/morphlib/morphloader.py @@ -585,11 +585,24 @@ class MorphologyLoader(object): cls._validate_products(morphology['name'], morphology['products'], errors) + for key in MorphologyDumper.keyorder: + if key.endswith('-commands') and key in morphology: + cls._validate_commands(morphology['name'], key, + morphology[key], errors) + if len(errors) == 1: raise errors[0] elif errors: raise MultipleValidationErrors(morphology['name'], errors) + @classmethod + def _validate_commands(cls, morphology_name, key, commands, errors): + for cmd_index, cmd in enumerate(commands): + if not isinstance(cmd, basestring): + e = InvalidTypeError('%s[%d]' % (key, cmd_index), + str, type(cmd), morphology_name) + errors.append(e) + @classmethod def _validate_products(cls, morphology_name, products, errors): '''Validate the products field is of the correct type.''' -- cgit v1.2.1