Closed lukew-cogapp closed 2 months ago
Could you share the full stack trace of the error @lukew-cogapp ?
Hi @janhenckens I'm afraid not at the moment, once we have this I'll reply here with it.
Hi @janhenckens
Here's the full trace:
Stack trace:
#0 /var/www/html/vendor/algolia/algoliasearch-client-php/src/RetryStrategy/ApiWrapper.php(152): Algolia\AlgoliaSearch\RetryStrategy\ApiWrapper->createRequest('POST', Object(Algolia\AlgoliaSearch\Http\Psr7\Uri), Array, false)
#1 /var/www/html/vendor/algolia/algoliasearch-client-php/src/RetryStrategy/ApiWrapper.php(100): Algolia\AlgoliaSearch\RetryStrategy\ApiWrapper->request('POST', '/1/indexes/site...', Object(Algolia\AlgoliaSearch\RequestOptions\RequestOptions), Array, 30, Array)
#2 /var/www/html/vendor/algolia/algoliasearch-client-php/src/SearchIndex.php(298): Algolia\AlgoliaSearch\RetryStrategy\ApiWrapper->write('POST', '/1/indexes/site...', Array, Object(Algolia\AlgoliaSearch\RequestOptions\RequestOptions))
#3 /var/www/html/vendor/algolia/algoliasearch-client-php/src/SearchIndex.php(338): Algolia\AlgoliaSearch\SearchIndex->rawBatch(Array, Array)
#4 /var/www/html/vendor/algolia/algoliasearch-client-php/src/SearchIndex.php(183): Algolia\AlgoliaSearch\SearchIndex->splitIntoBatches('updateObject', Array, Array)
#5 /var/www/html/vendor/studioespresso/craft-scout/src/engines/AlgoliaEngine.php(52): Algolia\AlgoliaSearch\SearchIndex->saveObjects(Array)
#6 /var/www/html/vendor/studioespresso/craft-scout/src/jobs/MakeSearchable.php(30): rias\scout\engines\AlgoliaEngine->update(Object(Illuminate\Support\Collection))
#7 /var/www/html/vendor/yiisoft/yii2-queue/src/Queue.php(243): rias\scout\jobs\MakeSearchable->execute(Object(craft\queue\Queue))
#8 /var/www/html/vendor/yiisoft/yii2-queue/src/cli/Queue.php(147): yii\queue\Queue->handleMessage(4625957, 'O:30:"rias\\scou...', 300, 1)
#9 /var/www/html/vendor/craftcms/cms/src/queue/Queue.php(191): yii\queue\cli\Queue->handleMessage(4625957, 'O:30:"rias\\scou...', 300, 1)
#10 /var/www/html/vendor/craftcms/cms/src/queue/Queue.php(166): craft\queue\Queue->executeJob()
#11 [internal function]: craft\queue\Queue->craft\queue\{closure}(Object(Closure))
#12 /var/www/html/vendor/yiisoft/yii2-queue/src/cli/Queue.php(114): call_user_func(Object(Closure), Object(Closure))
#13 /var/www/html/vendor/craftcms/cms/src/queue/Queue.php(164): yii\queue\cli\Queue->runWorker(Object(Closure))
#14 /var/www/html/vendor/craftcms/cms/src/controllers/QueueController.php(82): craft\queue\Queue->run()
#15 /var/www/html/vendor/craftcms/cms/src/controllers/QueueController.php(103): craft\controllers\QueueController->actionRun()
#16 [internal function]: craft\controllers\QueueController->actionRetry()
#17 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#18 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#19 /var/www/html/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('retry', Array)
#20 /var/www/html/vendor/craftcms/cms/src/web/Application.php(341): yii\base\Module->runAction('queue/retry', Array)
#21 /var/www/html/vendor/craftcms/cms/src/web/Application.php(642): craft\web\Application->runAction('queue/retry', Array)
#22 /var/www/html/vendor/craftcms/cms/src/web/Application.php(303): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#23 /var/www/html/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#24 /var/www/html/web/index.php(26): yii\base\Application->run()
#25 {main} {"memory":14680520,"exception":"[object] (InvalidArgumentException(code: 0): json_encode error: Malformed UTF-8 characters, possibly incorrectly encoded at /var/www/html/vendor/algolia/algoliasearch-client-php/src/RetryStrategy/ApiWrapper.php:253)"}
And we have also updated to 4.1.1 and the same issue persists
After some dirty debugging of the Algolia library, it looks like it's struggling on unmatched smart quotes i.e
’
This text fails by: it’s also a good choice:
Ilex crenata ‘Convexa’ looks nothing like a traditional holly, but instead looks like a box (Buxus) plant. It can be used as an alternative to box, where box blight and box tree moth have become a problem, as the foliage is tightly arranged and it tolerates regular pruning. It’s slow-growing nature makes it an excellent candidate for anyone looking for structure without needing to carry out too much maintenance. If you have a balcony or patio, it’s also a good choice for containers.
But note that if I change to it's
(normal single quote), everything works as expected. The odd thing is that ‘Convexa’
(which includes matched smart quotes) works just fine and causes no issues.
I appreciate this is happening in the Algolia library and not yours, but if there's a workaround you could add that means the client can still use smart quotes, that would be great.
nevermind, we've found the real issue, there was code elsewhere that was splitting strings after 3000 characters, if the split was on a special character (like a smart/curly quote) it would create a broken character. I'll close this off.
Good you hear you found the issue @lukew-cogapp !
Hello,
We're using Craft CMS 4.8.9 and Scout 3.3.3.
Some of our entries are not indexing to Algolia and we get:
Error: json_encode error: Malformed UTF-8 characters, possibly incorrectly encoded
Craft is fine saving these entires to the DB, here's one of the entries in question (frontend): https://www.nts.org.uk/stories/vital-support-for-our-national-nature-reserves
Our assumption is that there's something in the content that isn't being sanitised, our initial thoughts were perhaps the use of the different single quote style but we have an earlier version in the index that was fine: