Error: Cookie 'alc_enc' can't be set when trying to run static publishing task, but queuing the task works

Silverstripe Version: SS5.3

Question:

I have a weird problem - when I run sake dev/tasks/SilverStripe-StaticPublishQueue-Task-StaticCacheFullBuildTask on CLI (or add the task via CMS > Jobs or select ‘run’ on the job via mysite.com/dev/tasks), then run sake dev/tasks/ProcessJobQueueTask on CLI, I get the following error:

Cookie ‘alc_enc’ can’t be set. The site started outputting content at line 108 in /var/www/html/vendor/silverstripe/framework/src/Dev/TaskRunner.php at /var/www/html/vendor/silverstripe/framework/src/Control/CookieJar.php:181

However, if I queue the job via CLI dev/tasks/queue/SilverStripe-StaticPublishQueue-Task-StaticCacheFullBuildTask or select the ‘queue’ option in mysite.com/dev/tasks, then run sake dev/tasks/ProcessJobQueueTask on CLI, the full cache build task runs just fine.

The alc_enc cookie error also occurs when jobs are added via a page being republished in the CMS.

I only noticed this error appearing after a recent SS upgrade. Any ideas on what’s going on here would be most welcome.

For reference, line 108 of TaskRunner.php is:

printf(Director::is_cli() ? "%s\n\n" : '<h1>%s</h1>', $content);

Ok, I’ve traced it down to the Static Publisher module interacting with the Cloudinary module.

See bug report here:

Steps to reproduce:

results in error:

error-log.ERROR: Cookie 'alc_enc' can't be set. The site started outputting content at line 108 in /var/www/html/vendor/silverstripe/framework/src/Dev/TaskRunner.php {"exception":"[object] (LogicException(code: 0): Cookie 'alc_enc' can't be set. The site started outputting content at line 108 in /var/www/html/vendor/silverstripe/framework/src/Dev/TaskRunner.php at /var/www/html/vendor/silverstripe/framework/src/Control/CookieJar.php:181)"} []
[2025-03-13T12:40:48.359764+13:00] error-log.WARNING: Job paused at 2025-03-13 12:40:48 [] []

I’ve tried to track down what causes this in the Cloudinary module, but cannot find it. However, queuing the build task (instead of running it) does not produce the error, ie.

  • queue sake dev/tasks/queue/SilverStripe-StaticPublishQueue-Task-StaticCacheFullBuildTask
  • then run sake dev/tasks/ProcessJobQueueTask

appears to work fine.

Also, if I add the following to _config.php, it suppresses the error - maybe this is all that’s needed somewhere in the Cloudinary module, I’m just not sure where.

use SilverStripe\Control\Cookie;
Cookie::config()->set('report_errors', false);

Hoping someone can help with this, as this bug is currently causing each build job triggered by a page republish to result in that error and fail. Is it ok to simply leave the Cookie::config()->set('report_errors', false); setting in my _config.php or is this a bad idea?