Unable to decode output into JSON: Syntax error
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3223751. -->
Reported by: [mhavelant](https://www.drupal.org/user/3331139)
Related to !5
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>I'm receiving <code> Unable to decode output into JSON: Syntax error</code> errors from drush commands that are using the batch api internally. This results in the command to return a non-0 exit code breaking automation.</p>
<h4 id="summary-steps-reproduce">Steps to reproduce</h4>
<p>On a multilingual site, </p>
<ul>
<li>install twig_tweak (or any module with missing translations)</li>
<li>install monolog</li>
<li>set up a custom handler that logs to <code>php://stderr</code> using <code>@monolog.formatter.json</code></li>
<li>use <code>drush locale:check.</code></li>
</ul>
<p>After this, the above error is shown.<br>
Note, although this is one way to reproduce, the main reason for this error is the batch process printing out multiple lines of JSON, then Drupal trying to json_decode the output of the process. Any setup that makes any batch process log at least 1 line of JSON output will encounter the same error.</p>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>Fix the issue.</p>
<h3 id="summary-remaining-tasks">Remaining tasks</h3>
<p>Fix the issue.</p>
<h3 id="summary-ui-changes">User interface changes</h3>
<p>-</p>
<h3 id="summary-api-changes">API changes</h3>
<p>-</p>
<h3 id="summary-data-model-changes">Data model changes</h3>
<p>-</p>
<h3 id="summary-additional-info">Additional information</h3>
<p>Stack trace of the error:</p>
<pre>Exception trace:<br> at /var/www/html/vendor/consolidation/site-process/src/ProcessBase.php:171<br> Consolidation\SiteProcess\ProcessBase->getOutputAsJson() at /var/www/html/vendor/drush/drush/includes/batch.inc:157<br> _drush_backend_batch_process() at /var/www/html/vendor/drush/drush/includes/batch.inc:80<br> drush_backend_batch_process() at /var/www/html/vendor/drush/drush/src/Drupal/Commands/core/LocaleCommands.php:89<br> Drush\Drupal\Commands\core\LocaleCommands->check() at n/a:n/a<br> call_user_func_array() at /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php:257<br> Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback() at /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php:212<br> Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter() at /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php:176<br> Consolidation\AnnotatedCommand\CommandProcessor->process() at /var/www/html/vendor/consolidation/annotated-command/src/AnnotatedCommand.php:311<br> Consolidation\AnnotatedCommand\AnnotatedCommand->execute() at /var/www/html/vendor/symfony/console/Command/Command.php:255<br> Symfony\Component\Console\Command\Command->run() at /var/www/html/vendor/symfony/console/Application.php:1027<br> Symfony\Component\Console\Application->doRunCommand() at /var/www/html/vendor/symfony/console/Application.php:273<br> Symfony\Component\Console\Application->doRun() at /var/www/html/vendor/symfony/console/Application.php:149<br> Symfony\Component\Console\Application->run() at /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php:118<br> Drush\Runtime\Runtime->doRun() at /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php:48<br> Drush\Runtime\Runtime->run() at /var/www/html/vendor/drush/drush/drush.php:72<br> require() at /var/www/html/vendor/drush/drush/drush:4</pre>
issue