symfony/symfony · error · LogicException

Using the JSON format to debug environment variables is not

Error message

Using the JSON format to debug environment variables is not supported.

What it means

Thrown by `JsonDescriptor::describeContainerEnvVars()` when the `debug:container` command is asked to list environment variables (`--env-vars` or `--env-var`) using the `--format=json` output. Environment-variable debugging relies on runtime introspection that only the text descriptor implements, so the JSON descriptor rejects it with a `LogicException`.

Source

Thrown at src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php:167

    {
        $this->writeData($this->getCallableData($callable), $options);
    }

    protected function describeContainerParameter(mixed $parameter, ?array $deprecation, array $options = []): void
    {
        $key = $options['parameter'] ?? '';
        $data = [$key => $parameter];

        if ($deprecation) {
            $data['_deprecation'] = \sprintf('Since %s %s: %s', $deprecation[0], $deprecation[1], \sprintf(...\array_slice($deprecation, 2)));
        }

        $this->writeData($data, $options);
    }

    protected function describeContainerEnvVars(array $envs, array $options = []): void
    {
        throw new LogicException('Using the JSON format to debug environment variables is not supported.');
    }

    protected function describeContainerDeprecations(ContainerBuilder $container, array $options = []): void
    {
        $containerDeprecationFilePath = \sprintf('%s/%sDeprecations.log', $container->getParameter('kernel.build_dir'), $container->getParameter('kernel.container_class'));
        if (!file_exists($containerDeprecationFilePath)) {
            throw new RuntimeException('The deprecation file does not exist, please try warming the cache first.');
        }

        $logs = unserialize(file_get_contents($containerDeprecationFilePath), ['allowed_classes' => false]);

        $formattedLogs = [];
        $remainingCount = 0;
        foreach ($logs as $log) {
            $formattedLogs[] = [
                'message' => $log['message'],
                'file' => $log['file'],
                'line' => $log['line'],

View on GitHub (pinned to 698e28026c)

Solutions

  1. Use the default text format (`--format=txt` or omit `--format`) for env-var debugging.
  2. Parse the text output in your script, or read env vars directly via `$_SERVER`/`getenv()` instead of the command.

Example fix

// before
php bin/console debug:container --env-vars --format=json

// after
php bin/console debug:container --env-vars
Defensive patterns

Strategy: validation

Validate before calling

// Never combine --env-vars with --format=json.
$format = $input->getOption('format');
if (($input->getOption('env-vars') || $input->getOption('env-var')) && $format === 'json') {
    // switch to txt or remove env-vars
}

Try / catch

try {
    $command->run($input, $output);
} catch (\Symfony\Component\Console\Exception\LogicException $e) {
    // unsupported format combo; retry with txt
}

Prevention

When it happens

Trigger: Running `php bin/console debug:container --env-vars --format=json` or `debug:container --env-var=APP_ENV --format=json`. The JSON descriptor's `describeContainerEnvVars` override unconditionally throws.

Common situations: Scripting/CI pipelines that default to `--format=json` for machine-readable output and try to inspect env vars with the same flag.

Related errors


AI-assisted analysis of symfony/symfony@698e28026c (2026-08-06). Data as JSON: /api/errors/b7472a08f73c873b. Report an issue: GitHub.