"Current variable is not valid" for same input

Hello everyone, I am trying to set a variable with the value returned by my custom function generateAffiliationLink, but it's not working.

As you can see, when I assign the value of PageState.product.photo.first to the imageUrl parameter of my custom function generateAffiliationLink, I encounter an error: "Custom variable is not valid."

On the other hand, if I use the same variable PageState.product.photo.first as the preview parameter in the "Generate Custom Page" link (action), I don't encounter this error.

I don't understand why this error occurs, given that the input variable (PageState.product.photo.first) and the parameter type asked by both functions (Generate Custom Page and generateAffiliationLink) are Strings.

String generateAffiliationLink(
  String productRef,
  String title,
  String? imageUrl,
  String description,
) 

Where can the error come from?

Thanks for your help :)

2