Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Application.php

function Application::doRenderThrowable

1 call to Application::doRenderThrowable()
Application::renderThrowable in vendor/symfony/console/Application.php

File

vendor/symfony/console/Application.php, line 854

Class

Application
An Application is the container for a collection of commands.

Namespace

Symfony\Component\Console

Code

protected function doRenderThrowable(\Throwable $e, OutputInterface $output) : void {
    do {
        $message = trim($e->getMessage());
        if ('' === $message || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
            $class = get_debug_type($e);
            $title = \sprintf('  [%s%s]  ', $class, 0 !== ($code = $e->getCode()) ? ' (' . $code . ')' : '');
            $len = Helper::width($title);
        }
        else {
            $len = 0;
        }
        if (str_contains($message, "@anonymous\x00")) {
            $message = preg_replace_callback('/[a-zA-Z_\\x7f-\\xff][\\\\a-zA-Z0-9_\\x7f-\\xff]*+@anonymous\\x00.*?\\.php(?:0x?|:[0-9]++\\$)?[0-9a-fA-F]++/', fn($m) => class_exists($m[0], false) ? ((get_parent_class($m[0]) ?: key(class_implements($m[0]))) ?: 'class') . '@anonymous' : $m[0], $message);
        }
        $width = $this->terminal
            ->getWidth() ? $this->terminal
            ->getWidth() - 1 : \PHP_INT_MAX;
        $lines = [];
        foreach ('' !== $message ? preg_split('/\\r?\\n/', $message) : [] as $line) {
            foreach ($this->splitStringByWidth($line, $width - 4) as $line) {
                // pre-format lines to get the right string length
                $lineLength = Helper::width($line) + 4;
                $lines[] = [
                    $line,
                    $lineLength,
                ];
                $len = max($lineLength, $len);
            }
        }
        $messages = [];
        if (!$e instanceof ExceptionInterface || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
            $messages[] = \sprintf('<comment>%s</comment>', OutputFormatter::escape(\sprintf('In %s line %s:', basename($e->getFile()) ?: 'n/a', $e->getLine() ?: 'n/a')));
        }
        $messages[] = $emptyLine = \sprintf('<error>%s</error>', str_repeat(' ', $len));
        if ('' === $message || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
            $messages[] = \sprintf('<error>%s%s</error>', $title, str_repeat(' ', max(0, $len - Helper::width($title))));
        }
        foreach ($lines as $line) {
            $messages[] = \sprintf('<error>  %s  %s</error>', OutputFormatter::escape($line[0]), str_repeat(' ', $len - $line[1]));
        }
        $messages[] = $emptyLine;
        $messages[] = '';
        $output->writeln($messages, OutputInterface::VERBOSITY_QUIET);
        if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
            $output->writeln('<comment>Exception trace:</comment>', OutputInterface::VERBOSITY_QUIET);
            // exception related properties
            $trace = $e->getTrace();
            array_unshift($trace, [
                'function' => '',
                'file' => $e->getFile() ?: 'n/a',
                'line' => $e->getLine() ?: 'n/a',
                'args' => [],
            ]);
            for ($i = 0, $count = \count($trace); $i < $count; ++$i) {
                $class = $trace[$i]['class'] ?? '';
                $type = $trace[$i]['type'] ?? '';
                $function = $trace[$i]['function'] ?? '';
                $file = $trace[$i]['file'] ?? 'n/a';
                $line = $trace[$i]['line'] ?? 'n/a';
                $output->writeln(\sprintf(' %s%s at <info>%s:%s</info>', $class, $function ? $type . $function . '()' : '', $file, $line), OutputInterface::VERBOSITY_QUIET);
            }
            $output->writeln('', OutputInterface::VERBOSITY_QUIET);
        }
    } while ($e = $e->getPrevious());
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal