From 4e0b50376f99d1a4e551e630020c97db6a801ef8 Mon Sep 17 00:00:00 2001 From: Scott Huberty Date: Tue, 8 Oct 2024 10:53:22 -0700 Subject: [PATCH] FIX: improve evaluate_connect_function error handling. This incorporates Chris's suggestions from https://github.com/nipy/nipype/pull/3655#issuecomment-2395502745 Except I raise a new error and include the original error message (instead of revising the original error message). Co-authored-by: Chris Markiewicz --- nipype/pipeline/engine/utils.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/nipype/pipeline/engine/utils.py b/nipype/pipeline/engine/utils.py index 7bf84aadc7..80593c0fa8 100644 --- a/nipype/pipeline/engine/utils.py +++ b/nipype/pipeline/engine/utils.py @@ -689,15 +689,10 @@ def evaluate_connect_function(function_source, args, first_arg): try: output_value = func(first_arg, *list(args)) except NameError as e: - if e.args[0].endswith("is not defined"): - e.args = ( - e.args[0], - ( - "Due to engine constraints all imports have to be done " - "inside each function definition" - ), - ) - raise e + raise NameError( + f"{e}: Due to engine constraints all imports have to be done inside each " + " function definition." + ) return output_value