diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2012-07-26 17:14:45 +0100 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2012-07-31 18:08:20 +0200 |
commit | eb08ef73cf2a200fe4279b94792d7353b61027b5 (patch) | |
tree | d71545b3e0b8778c765921a173b348a2ac96542a /morphlib | |
parent | c65369a965f75b7ce215138480b73c796b671fa1 (diff) | |
download | morph-eb08ef73cf2a200fe4279b94792d7353b61027b5.tar.gz |
Raise clearer error on morphology parse errors
Diffstat (limited to 'morphlib')
-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') + |