Search Pattern Error since Google Scripts V8 Update

半城伤御伤魂 提交于 2020-03-16 07:36:44

问题


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]);
}

回答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]));
}



回答2:


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

Thanks!



来源:https://stackoverflow.com/questions/60551160/search-pattern-error-since-google-scripts-v8-update

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!