summaryrefslogtreecommitdiff
path: root/morphlib/morph2.py
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2013-02-08 10:48:20 +0000
committerSam Thursfield <sam.thursfield@codethink.co.uk>2013-02-18 11:24:01 +0000
commit76826aa85806243c778a78611fdd8a9239496396 (patch)
tree3f4b7f565309f6eabefaf313a6456ea10f85e307 /morphlib/morph2.py
parent0e80ed76854e88dc93ca9d5a59bd11b99932e83a (diff)
downloadmorph-76826aa85806243c778a78611fdd8a9239496396.tar.gz
Detect and abort on empty morphologies
If given an empty string to parse yamlparse.load() will return None, but this breaks code further down that expects to be dealing with a dict. Raise an exception to avoid crashing. Also, avoid catching 'Exception' when we only want to catch JSON parse errors.
Diffstat (limited to 'morphlib/morph2.py')
-rw-r--r--morphlib/morph2.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/morphlib/morph2.py b/morphlib/morph2.py
index 26813925..a32ecbb9 100644
--- a/morphlib/morph2.py
+++ b/morphlib/morph2.py
@@ -74,6 +74,10 @@ class Morphology(object):
except ValueError as e: # pragma: no cover
self._dict = morphlib.yamlparse.load(text)
self._dumper = morphlib.yamlparse.dump
+
+ if data is None:
+ raise morphlib.YAMLError("Morphology is empty")
+
self._set_defaults()
self._validate_children()