diff --git a/ete4/parser/newick.pyx b/ete4/parser/newick.pyx index 85281b4d1..a61c79e2c 100644 --- a/ete4/parser/newick.pyx +++ b/ete4/parser/newick.pyx @@ -239,6 +239,7 @@ def read_props(str text, long pos, is_leaf, dict parser, check_req=False): except (AssertionError, ValueError) as e: raise NewickError('parsing %r: %s' % (p0_str, e)) + p1_str = '' # always defined (like p0_str) so error messages don't fail try: if pos < len(text) and text[pos] == ':': pos = skip_spaces_and_comments(text, pos+1) diff --git a/tests/test_tree.py b/tests/test_tree.py index 74d45c68b..078a9c4be 100644 --- a/tests/test_tree.py +++ b/tests/test_tree.py @@ -345,6 +345,12 @@ def test_newick_formats(self): # unsupported newick stream self.assertRaises(Exception, Tree, [1,2,3]) + def test_newick_missing_required_value(self): + # A strict parser with a required second field (dist/support) must + # raise a clean NewickError when that value is missing, not crash with + # UnboundLocalError from the error handler (issue #799). + self.assertRaises(NewickError, Tree, '(A);', parser=3) + def test_newick_multisupport(self): nw = '((a,b)2/3:4,(c,d)5/6:7);' t = Tree(nw, parser='multisupport')