1

Ever since google forced the update "This project is running on our new Apps Script runtime powered by Chrome V8." I'm getting the following error and I don't understand why.

"Exception: Invalid argument: searchPattern at recreateReferral(recreateReferral:82:13)"

Here is the snippet of code: Line 82 starts with newBody.

for(i = 0; i <=16; i++) {
newBody.replaceText(fields[0][i], newData[0][i]);
}
Rubén
  • 34,714
  • 9
  • 70
  • 166
Dave
  • 11
  • 3
  • 1
    What is the value of `fields[0][i]`? – jmrk Mar 05 '20 at 17:59
  • 1
    Please add a [mcve]. – Rubén Mar 05 '20 at 18:09
  • There appear to be some issues regarding this type of error but to be honest the reports aren't very specific and I suspect they'll be hard to reproduce so it might be best to report it as an issue but please provide them with a lot more information than you provided to us. [Issue Tracker](https://issuetracker.google.com/issues?q=componentid:191640%2B) [mcve] – Cooper Mar 05 '20 at 18:31

2 Answers2

1

Possible cause(s):

  • Your original rhino script is buggy, because it doesn't check the type of the argument fields[0][i] and newData[0][i].

  • Empty string "" and null also throw this error.

Solution:

  • Cast type and check length of the argument before feeding it to replaceText()

Snippet:

if (String(fields[0][i]).length){
  newBody.replaceText(String(fields[0][i]), String(newData[0][i]));
}
Community
  • 1
  • 1
TheMaster
  • 45,448
  • 6
  • 62
  • 85
  • 1
    Thanks for the answer. I had a feeling that you would be able to provide some insight here. – Cooper Mar 05 '20 at 19:06
  • @Cooper I'm still not sure about this as this isn't a `Type error`.So, take the solution with caution. – TheMaster Mar 05 '20 at 19:39
  • 1
    @Cooper I think I found it. Tested and confirmed that It happens mainly due to empty strings. Apologies for the confusion. – TheMaster Mar 05 '20 at 20:01
0

I figured it out. It was the empty parts of the string as someone above suggested.

Thanks!

Dave
  • 11
  • 3