Skip to content

Commit 5b0e74c

Browse files
committed
fix: addresses issue #1446 (solution from @ashgillman in #1551)
1 parent 4fa120b commit 5b0e74c

File tree

2 files changed

+48
-5
lines changed

2 files changed

+48
-5
lines changed

nipype/pipeline/engine/nodes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,8 @@ def _node_runner(self, nodes, updatehash=False):
11281128
err = None
11291129
try:
11301130
node.run(updatehash=updatehash)
1131-
except Exception as err:
1131+
except Exception as e:
1132+
err = str(e)
11321133
if str2bool(self.config['execution']['stop_on_first_crash']):
11331134
raise
11341135
finally:

nipype/pipeline/engine/tests/test_utils.py

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ def test_provenance(tmpdir):
339339

340340

341341
def test_mapnode_crash(tmpdir):
342+
"""Test mapnode crash when stop_on_first_crash is True"""
342343
def myfunction(string):
343344
return string + 'meh'
344345
node = pe.MapNode(niu.Function(input_names=['WRONG'],
@@ -350,14 +351,55 @@ def myfunction(string):
350351
node.inputs.WRONG = ['string' + str(i) for i in range(3)]
351352
node.config = deepcopy(config._sections)
352353
node.config['execution']['stop_on_first_crash'] = True
353-
cwd = os.getcwd()
354-
node.base_dir = tmpdir
354+
node.base_dir = str(tmpdir)
355355

356356
error_raised = False
357357
try:
358358
node.run()
359359
except TypeError as e:
360360
error_raised = True
361-
os.chdir(cwd)
362-
rmtree(node.base_dir)
361+
assert error_raised
362+
363+
364+
def test_mapnode_crash2(tmpdir):
365+
"""Test mapnode crash when stop_on_first_crash is False"""
366+
def myfunction(string):
367+
return string + 'meh'
368+
node = pe.MapNode(niu.Function(input_names=['WRONG'],
369+
output_names=['newstring'],
370+
function=myfunction),
371+
iterfield=['WRONG'],
372+
name='myfunc')
373+
374+
node.inputs.WRONG = ['string' + str(i) for i in range(3)]
375+
node.base_dir = str(tmpdir)
376+
377+
error_raised = False
378+
try:
379+
node.run()
380+
except Exception as e:
381+
error_raised = True
382+
assert error_raised
383+
384+
385+
def test_mapnode_crash3(tmpdir):
386+
"""Test mapnode crash when mapnode is embedded in a workflow"""
387+
def myfunction(string):
388+
return string + 'meh'
389+
node = pe.MapNode(niu.Function(input_names=['WRONG'],
390+
output_names=['newstring'],
391+
function=myfunction),
392+
iterfield=['WRONG'],
393+
name='myfunc')
394+
395+
node.inputs.WRONG = ['string' + str(i) for i in range(3)]
396+
wf = pe.Workflow('test_mapnode_crash')
397+
wf.add_nodes([node])
398+
wf.base_dir = str(tmpdir)
399+
400+
error_raised = False
401+
try:
402+
wf.run()
403+
except RuntimeError as e:
404+
error_raised = True
363405
assert error_raised

0 commit comments

Comments
 (0)