Hi, we had the same error, the same error message like the one you mention and it appeared on that part in our script where we used MapSubstring() function.
We resolved the problem by ensuring the mapping table has all the values that the function MapSubstring is going to encounter when applied. If we load, e.g. partial load with the first 10 records only and our mapping table has more rows, the problem appears. If we don't filter anything and the source mapping table contains all values, then there is no problem.