summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2012-08-01 09:47:40 +0100
committerRichard Maw <richard.maw@codethink.co.uk>2012-08-01 09:47:40 +0100
commit936fc1ec1cd9156f6aafdfcec391f12a6cf22603 (patch)
treed90db88cc73eb4b5e7dfb497a7a8f65986ba82d1
parentc65369a965f75b7ce215138480b73c796b671fa1 (diff)
parenteb08ef73cf2a200fe4279b94792d7353b61027b5 (diff)
downloadmorph-936fc1ec1cd9156f6aafdfcec391f12a6cf22603.tar.gz
Merge branch 'samthursfield/clearer-morphology-parse-errors' of git://roadtrain.codethink.co.uk/baserock/morph
Merged with a tweak to the layout, since the code style's display width is 79 characters, rather than 80.
-rw-r--r--morphlib/morphologyfactory.py8
-rw-r--r--morphlib/morphologyfactory_tests.py7
2 files changed, 13 insertions, 2 deletions
diff --git a/morphlib/morphologyfactory.py b/morphlib/morphologyfactory.py
index 925829e9..9e6a76f2 100644
--- a/morphlib/morphologyfactory.py
+++ b/morphlib/morphologyfactory.py
@@ -49,8 +49,12 @@ 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')
+