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