private function renderException(OutputInterface $output, $template, \Twig_Error $exception, $file = null) { $line = $exception->getTemplateLine(); if ($file) { $output->writeln(sprintf('<error>KO</error> in %s (line %s)', $file, $line)); } else { $output->writeln(sprintf('<error>KO</error> (line %s)', $line)); } foreach ($this->getContext($template, $line) as $no => $code) { $output->writeln(sprintf('%s %-6s %s', $no == $line ? '<error>>></error>' : ' ', $no, $code)); if ($no == $line) { $output->writeln(sprintf('<error>>> %s</error> ', $exception->getRawMessage())); } } }
private function enhanceTwigException(\Twig_Error $e, Document $document, $template = null) { if (-1 === $e->getTemplateLine()) { return new \RuntimeException($e->getRawMessage()); } $lines = explode(PHP_EOL, $document->getBody()); if (!$template || $template->getTemplateName() == $e->getTemplateFile()) { return new \RuntimeException(OutputFormatter::escape(sprintf('%s near "%s" near line %d.', $e->getRawMessage(), $lines[$e->getTemplateLine() - 1], $e->getTemplateLine()))); } return new \RuntimeException(OutputFormatter::escape(sprintf('%s in a string template line %d.', $e->getRawMessage(), $e->getTemplateLine()))); }
protected function renderException(OutputInterface $output, $file, \Twig_Error $exception) { $line = $exception->getTemplateLine(); $lines = $this->getContext($file, $line); $output->writeln(sprintf("<error>KO</error> in %s (line %s)", $file, $line)); foreach ($lines as $no => $code) { $output->writeln(sprintf("%s %-6s %s", $no == $line ? '<error>>></error>' : ' ', $no, $code)); if ($no == $line) { $output->writeln(sprintf('<error>>> %s</error> ', $exception->getRawMessage())); } } }
/** * Handles Twig syntax errors. * * @param \Twig_Error $exception * * @return null */ protected function handleTwigError(\Twig_Error $exception) { $templateFile = $exception->getTemplateFile(); $file = craft()->templates->findTemplate($templateFile); if (!$file) { $file = $templateFile; } $this->_error = $data = array('code' => 500, 'type' => Craft::t('Template Error'), 'errorCode' => $exception->getCode(), 'message' => $exception->getRawMessage(), 'file' => $file, 'line' => $exception->getTemplateLine(), 'trace' => '', 'traces' => null); if (!headers_sent()) { HeaderHelper::setHeader("HTTP/1.0 {$data['code']} " . $this->getHttpHeader($data['code'], get_class($exception))); } if ($exception instanceof \CHttpException || !YII_DEBUG) { $this->render('error', $data); } else { if ($this->isAjaxRequest()) { craft()->displayException($exception); } else { $this->render('exception', $data); } } }