From c0d7cadbfb449f87ed22d35d73ad8fc9f15e99d3 Mon Sep 17 00:00:00 2001 From: "Kshitij Chawla (kchawla-pi)" Date: Mon, 3 Sep 2018 12:05:23 +0200 Subject: [PATCH 1/2] Fixed: Missing substring should raise ValueError not KeyError - nipype issue# 2690 --- nipype/utils/spm_docs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nipype/utils/spm_docs.py b/nipype/utils/spm_docs.py index 4c71c05523..2a95a7ad83 100644 --- a/nipype/utils/spm_docs.py +++ b/nipype/utils/spm_docs.py @@ -59,5 +59,5 @@ def _strip_header(doc): 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) From 7f48e9483c19f0ad0d113cb70bcb3f8557ae6f84 Mon Sep 17 00:00:00 2001 From: "Kshitij Chawla (kchawla-pi)" Date: Mon, 17 Sep 2018 16:02:40 +0200 Subject: [PATCH 2/2] Reorganized exception catching in _strip_header() for better code clarity - Cleanup suggested by @effigies --- nipype/utils/spm_docs.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/nipype/utils/spm_docs.py b/nipype/utils/spm_docs.py index 2a95a7ad83..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 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]