The error happens after the script edits the contents of the google docs with item details.
The script fails to find the ending of docs content with search text '"},{"ty'
|
$position = StringInStr($extractedText, '"},{"ty') |
in my case, changing the search string to '"}},{"ty"' fixed the problem.