fixed message inconsistency

This commit is contained in:
Fabien Potencier
2015-10-26 19:17:27 +01:00
parent 0468a7ede4
commit 12ea20245c
4 changed files with 14 additions and 10 deletions
+6
View File
@@ -155,6 +155,12 @@ class Twig_Error extends Exception
throw new BadMethodCallException(sprintf('Method "Twig_Error::%s()" does not exist.', $method)); throw new BadMethodCallException(sprintf('Method "Twig_Error::%s()" does not exist.', $method));
} }
public function appendMessage($rawMessage)
{
$this->rawMessage .= $rawMessage;
$this->updateRepr();
}
/** /**
* @internal * @internal
*/ */
+1 -2
View File
@@ -29,8 +29,7 @@ class Twig_Error_Syntax extends Twig_Error
return; return;
} }
$this->rawMessage .= sprintf(' Did you mean "%s"?', implode('", "', $alternatives)); $this->appendMessage(sprintf(' Did you mean "%s"?', implode('", "', $alternatives)));
$this->updateRepr();
} }
/** /**
+5 -6
View File
@@ -166,16 +166,15 @@ class Twig_Parser implements Twig_ParserInterface
$subparser = $this->handlers->getTokenParser($token->getValue()); $subparser = $this->handlers->getTokenParser($token->getValue());
if (null === $subparser) { if (null === $subparser) {
if (null !== $test) { if (null !== $test) {
$error = sprintf('Unexpected tag name "%s"', $token->getValue()); $e = new Twig_Error_Syntax(sprintf('Unexpected "%s" tag', $token->getValue()), $token->getLine(), $this->getFilename());
if (is_array($test) && isset($test[0]) && $test[0] instanceof Twig_TokenParserInterface) { if (is_array($test) && isset($test[0]) && $test[0] instanceof Twig_TokenParserInterface) {
$error .= sprintf(' (expecting closing tag for the "%s" tag defined near line %s)', $test[0]->getTag(), $lineno); $e->appendMessage(sprintf(' (expecting closing tag for the "%s" tag defined near line %s).', $test[0]->getTag(), $lineno));
} }
} else {
throw new Twig_Error_Syntax($error, $token->getLine(), $this->getFilename());
}
$e = new Twig_Error_Syntax(sprintf('Unknown "%s" tag.', $token->getValue()), $token->getLine(), $this->getFilename()); $e = new Twig_Error_Syntax(sprintf('Unknown "%s" tag.', $token->getValue()), $token->getLine(), $this->getFilename());
$e->addMessageSuggestions($token->getValue(), array_keys($this->env->getTags())); $e->addMessageSuggestions($token->getValue(), array_keys($this->env->getTags()));
}
throw $e; throw $e;
} }
@@ -17,4 +17,4 @@ Exception for an unclosed tag
{% endblock %} {% endblock %}
--EXCEPTION-- --EXCEPTION--
Twig_Error_Syntax: Unexpected tag name "endblock" (expecting closing tag for the "if" tag defined near line 4) in "index.twig" at line 16 Twig_Error_Syntax: Unexpected "endblock" tag (expecting closing tag for the "if" tag defined near line 4) in "index.twig" at line 16.