diff options
author | Edward Cragg <edward.cragg@codethink.co.uk> | 2016-02-24 18:06:07 +0000 |
---|---|---|
committer | Edward Cragg <edward.cragg@codethink.co.uk> | 2016-02-25 15:56:26 +0000 |
commit | fb6dd955cbc7081f47dc43919075dc4eb3809172 (patch) | |
tree | 1f3dfdb83120559f55447427d900415ae5f4ee49 /morphlib | |
parent | 7e15ed7080c45f5283938e86af33fe4794b91b43 (diff) | |
download | morph-fb6dd955cbc7081f47dc43919075dc4eb3809172.tar.gz |
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 <type 'str'>, got <type
'NoneType'> in morphology linux-jetson-tk1
Change-Id: I45220e7deab8c7cd9351507bc998f7ff12797442
Diffstat (limited to 'morphlib')
-rw-r--r-- | morphlib/morphloader.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/morphlib/morphloader.py b/morphlib/morphloader.py index ff433d73..d7f0fe7e 100644 --- a/morphlib/morphloader.py +++ b/morphlib/morphloader.py @@ -585,12 +585,25 @@ 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.''' if (not isinstance(products, collections.Iterable) |