added filename when throwing an exception when we know it

This commit is contained in:
Fabien Potencier
2011-07-19 15:27:34 +02:00
parent 94ac20f155
commit e44ea9b0d4
2 changed files with 8 additions and 7 deletions
+4 -4
View File
@@ -121,7 +121,7 @@ class Twig_Parser implements Twig_ParserInterface
$token = $this->getCurrentToken();
if ($token->getType() !== Twig_Token::NAME_TYPE) {
throw new Twig_Error_Syntax('A block must start with a tag name', $token->getLine());
throw new Twig_Error_Syntax('A block must start with a tag name', $token->getLine(), $this->stream->getFilename());
}
if (null !== $test && call_user_func($test, $token)) {
@@ -138,7 +138,7 @@ class Twig_Parser implements Twig_ParserInterface
$subparser = $this->handlers->getTokenParser($token->getValue());
if (null === $subparser) {
throw new Twig_Error_Syntax(sprintf('Unknown tag name "%s"', $token->getValue()), $token->getLine());
throw new Twig_Error_Syntax(sprintf('Unknown tag name "%s"', $token->getValue()), $token->getLine(), $this->stream->getFilename());
}
$this->stream->next();
@@ -150,7 +150,7 @@ class Twig_Parser implements Twig_ParserInterface
break;
default:
throw new Twig_Error_Syntax('Lexer or parser ended up in unsupported state.');
throw new Twig_Error_Syntax('Lexer or parser ended up in unsupported state.', -1, $this->stream->getFilename());
}
}
@@ -301,7 +301,7 @@ class Twig_Parser implements Twig_ParserInterface
||
(!$node instanceof Twig_Node_Text && !$node instanceof Twig_Node_BlockReference && $node instanceof Twig_NodeOutputInterface)
) {
throw new Twig_Error_Syntax(sprintf('A template that extends another one cannot have a body (%s).', $node), $node->getLine());
throw new Twig_Error_Syntax(sprintf('A template that extends another one cannot have a body (%s).', $node), $node->getLine(), $this->stream->getFilename());
}
}
}
+4 -3
View File
@@ -53,7 +53,7 @@ class Twig_TokenStream
public function next()
{
if (!isset($this->tokens[++$this->current])) {
throw new Twig_Error_Syntax('Unexpected end of template');
throw new Twig_Error_Syntax('Unexpected end of template', -1, $this->filename);
}
return $this->tokens[$this->current - 1];
@@ -73,7 +73,8 @@ class Twig_TokenStream
$message ? $message.'. ' : '',
Twig_Token::typeToEnglish($token->getType(), $line), $token->getValue(),
Twig_Token::typeToEnglish($type, $line), $value ? sprintf(' with value "%s"', $value) : ''),
$line
$line,
$this->filename
);
}
$this->next();
@@ -91,7 +92,7 @@ class Twig_TokenStream
public function look($number = 1)
{
if (!isset($this->tokens[$this->current + $number])) {
throw new Twig_Error_Syntax('Unexpected end of template');
throw new Twig_Error_Syntax('Unexpected end of template', -1, $this->filename);
}
return $this->tokens[$this->current + $number];