From e8090a44c9d90cbfcdb3d82245628267e4fa2458 Mon Sep 17 00:00:00 2001 From: Celine Mercier Date: Fri, 15 Mar 2019 16:06:06 +0100 Subject: [PATCH] Fixed the ultimate bug with embl (and genbank) parsers: raising any exception in a python generator makes it unable to resume. So now, exceptions are not raised but printed, then functions return None and that's handled at higher level. --- python/obitools3/commands/import.pyx | 8 ++++++++ python/obitools3/parsers/embl.pyx | 12 ++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/python/obitools3/commands/import.pyx b/python/obitools3/commands/import.pyx index ecf8479..53a63b1 100755 --- a/python/obitools3/commands/import.pyx +++ b/python/obitools3/commands/import.pyx @@ -5,6 +5,7 @@ import os from obitools3.apps.progress cimport ProgressBar # @UnresolvedImport from obitools3.dms.view.view cimport View +from obitools3.dms.view import RollbackException from obitools3.dms.view.typed_view.view_NUC_SEQS cimport View_NUC_SEQS from obitools3.dms.column.column cimport Column from obitools3.dms.obiseq cimport Nuc_Seq @@ -153,6 +154,13 @@ def run(config): i = 0 for entry in entries : + if entry is None: # error or exception handled at lower level, not raised because Python generators can't resume after any exception is raised + if config['obi']['skiperror']: + i-=1 + continue + else: + raise RollbackException("obi import error, rollbacking view", view) + pb(i) if NUC_SEQS_view: diff --git a/python/obitools3/parsers/embl.pyx b/python/obitools3/parsers/embl.pyx index 070c911..84342da 100755 --- a/python/obitools3/parsers/embl.pyx +++ b/python/obitools3/parsers/embl.pyx @@ -45,7 +45,7 @@ def emblParser(bytes text): s = _seqMatcher.search(text).group() s = _cleanSeq.sub(b'', s).upper() - + acs = _acMatcher.search(text).group() acs = acs.replace(b';', b' ') acs = acs.split() @@ -55,11 +55,11 @@ def emblParser(bytes text): de = _deMatcher.search(header).group() de = _cleanDe.sub(b' ', de).strip().strip(b'.') - except AttributeError,e: - print('=======================================================') - print(text) - print('=======================================================') - raise e + except Exception as e: + print("\nCould not import sequence id:", text.split()[1], "(error raised:", e, ")") + # Do not raise any Exception if you need the possibility to resume the generator + # (Python generators can't resume after any exception is raised) + return None tags = {} extractTaxon(ft, tags)