private function LintCommand::renderException in Twig Tweak 3.x
Same name and namespace in other branches
- 3.1.x src/Command/LintCommand.php \Drupal\twig_tweak\Command\LintCommand::renderException()
1 call to LintCommand::renderException()
- LintCommand::displayTxt in src/
Command/ LintCommand.php
File
- src/
Command/ LintCommand.php, line 225
Class
- LintCommand
- Command that will validate your template syntax and output encountered errors.
Namespace
Drupal\twig_tweak\CommandCode
private function renderException(OutputInterface $output, string $template, Error $exception, string $file = null) {
$line = $exception
->getTemplateLine();
if ($file) {
$output
->text(sprintf('<error> ERROR </error> in %s (line %s)', $file, $line));
}
else {
$output
->text(sprintf('<error> ERROR </error> (line %s)', $line));
}
// If the line is not known (this might happen for deprecations if we fail at detecting the line for instance),
// we render the message without context, to ensure the message is displayed.
if ($line <= 0) {
$output
->text(sprintf('<error> >> %s</error> ', $exception
->getRawMessage()));
return;
}
foreach ($this
->getContext($template, $line) as $lineNumber => $code) {
$output
->text(sprintf('%s %-6s %s', $lineNumber === $line ? '<error> >> </error>' : ' ', $lineNumber, $code));
if ($lineNumber === $line) {
$output
->text(sprintf('<error> >> %s</error> ', $exception
->getRawMessage()));
}
}
}