diff options
-rw-r--r-- | morphlib/morphologyfactory.py | 7 | ||||
-rw-r--r-- | morphlib/morphologyfactory_tests.py | 7 |
2 files changed, 12 insertions, 2 deletions
diff --git a/morphlib/morphologyfactory.py b/morphlib/morphologyfactory.py index 925829e9..dd884865 100644 --- a/morphlib/morphologyfactory.py +++ b/morphlib/morphologyfactory.py @@ -49,8 +49,11 @@ class MorphologyFactory(object): except: text = self._autodetect_text(reponame, sha1, filename) - morphology = morphlib.morph2.Morphology(text) - + try: + morphology = morphlib.morph2.Morphology(text) + except ValueError as e: + raise morphlib.Error("Error parsing %s: %s" % (filename, e.message)) + method_name = '_check_and_tweak_%s' % morphology['kind'] if hasattr(self, method_name): method = getattr(self, method_name) diff --git a/morphlib/morphologyfactory_tests.py b/morphlib/morphologyfactory_tests.py index cc45bb21..06cfc5c3 100644 --- a/morphlib/morphologyfactory_tests.py +++ b/morphlib/morphologyfactory_tests.py @@ -63,6 +63,9 @@ class FakeLocalRepo(object): "system-kind": "%(system_kind)s", "arch": "%(arch)s" }''', + 'parse-error.morph': '''{ + "name" + }''', } def __init__(self): @@ -230,3 +233,7 @@ class MorphologyFactoryTests(unittest.TestCase): self.assertRaises(morphlib.Error, self.mf.get_morphology, 'reponame', 'sha1', 'system.morph') + def test_fails_on_parse_error(self): + self.assertRaises(morphlib.Error, self.mf.get_morphology, + 'reponame', 'sha1', 'parse-error.morph') + |