diff options
author | Tiago Gomes <tiago.gomes@codethink.co.uk> | 2015-12-04 17:54:52 +0000 |
---|---|---|
committer | Pedro Alvarez <pedro.alvarez@codethink.co.uk> | 2016-03-24 23:54:00 +0000 |
commit | 23b363c55c755f648ae38b61f09253860bfc61d3 (patch) | |
tree | e2d1a577b0048d11329db5f794c66ae1e800ef53 /morphlib/defaults.py | |
parent | 48e4a7941a4c1351076a2edf23274b41b19eab19 (diff) | |
download | morph-23b363c55c755f648ae38b61f09253860bfc61d3.tar.gz |
Use jsonschema to validate the morphs
Use jsonschema to do a first stage of validation of the morphologies.
Example error messages:
ERROR: strata/core.morph: core->build-depends: 'foo' is not of type
'array'
ERROR: strata/core.morph: core: 'name' is a required property
ERROR: strata/core.morph: core: Additional properties are not allowed
('extra-field' was unexpected)
ERROR: strata/core.morph: core->chunks[0]->name: 1111 is not of type
'string'
ERROR: strata/core.morph: core->chunks[0]: 'repo' is a required property
on {'morph': 'strata/core/gdbm.morph', 'ref':
'e5faeaaf75ecfb705a9b643b3e4cb881ebb69f48', 'unpetrify-ref':
'gdbm-1.11', 'name': 'gdbm'}
ERROR: strata/core.morph: core->chunks[0]: Additional properties are not
allowed ('extra-field' was unexpected) on {'repo':
'upstream:gdbm-tarball', 'extra-field': None, 'name': 'gdbm', 'morph':
'strata/core/gdbm.morph', 'ref':
'e5faeaaf75ecfb705a9b643b3e4cb881ebb69f48', 'unpetrify-ref':
'gdbm-1.11'}
Change-Id: If9fd488e16db35130d074492a93754a447ea98e1
Diffstat (limited to 'morphlib/defaults.py')
-rw-r--r-- | morphlib/defaults.py | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/morphlib/defaults.py b/morphlib/defaults.py index 86828baa..ee90956e 100644 --- a/morphlib/defaults.py +++ b/morphlib/defaults.py @@ -16,7 +16,6 @@ import cliapp -import jsonschema import yaml import os @@ -53,12 +52,9 @@ class Defaults(object): # It's OK to be empty, I guess. return build_systems, split_rules - try: - # It would be nice if this could give line numbers when it spotted - # errors. Seems tricky. - jsonschema.validate(data, self.schema) - except jsonschema.ValidationError as e: - raise cliapp.AppException('Invalid DEFAULTS file: %s' % e.message) + error = morphlib.util.validate_json(data, self.schema, 'DEFAULTS') + if error: + raise cliapp.AppException(error) build_system_data = data.get('build-systems', {}) for name, commands in build_system_data.items(): |