diff --git a/nipype/utils/spm_docs.py b/nipype/utils/spm_docs.py index 4c71c05523..12169b482b 100644 --- a/nipype/utils/spm_docs.py +++ b/nipype/utils/spm_docs.py @@ -51,13 +51,14 @@ def _strip_header(doc): cruft = '\x1b' try: index = doc.index(hdr) - index += len(hdr) - index += 1 - doc = doc[index:] - try: - index = doc.index(cruft) - except ValueError: - index = len(doc) - return doc[:index] - except KeyError as e: + except ValueError as e: raise_from(IOError('This docstring was not generated by Nipype!\n'), e) + + index += len(hdr) + index += 1 + doc = doc[index:] + try: + index = doc.index(cruft) + except ValueError: + index = len(doc) + return doc[:index]