ZF-12012: Make the TMX parser output the filename when throwing an exception


When parsing of an TMX file fails, an exception is thrown that reports the error and the line of the TMX file that was processed, but not the name of the TMX file. Instead, the (pretty useless) name of the TMX parser given.

This patch adds the filename to the error message, so one does know from the error message which TMX file could not be parsed (and then take a look at the TMX file).

Error-message before patch:

[exec] Zend_Translate_Exception: XML error: Not well-formed (invalid token) at line 1 in library/Zend/Translate/Adapter/Tmx.php on line 82

after patch:

[exec] Zend_Translate_Exception: XML error: Not well-formed (invalid token) at line 1 of file application/tmx/svn-commit.tmp in library/Zend/Translate/Adapter/Tmx.php on line 83

Please review the attached patch.


Huh, now how to add a patch here. I'll just post it as comment.

Index: library/Zend/Translate/Adapter/Tmx.php

--- library/Zend/Translate/Adapter/Tmx.php (revision 3015) +++ library/Zend/Translate/Adapter/Tmx.php (working copy) @@ -74,9 +74,10 @@ xml_set_character_data_handler($this->_file, "_contentElement");

     if (!xml_parse($this->_file, file_get_contents($filename))) {

- $ex = sprintf('XML error: %s at line %d', + $ex = sprintf('XML error: %s at line %d of file %s', xml_error_string(xml_get_error_code($this->_file)), - xml_get_current_line_number($this->_file)); + xml_get_current_line_number($this->_file), + $filename); xml_parser_free($this->_file); require_once 'Zend/Translate/Exception.php'; throw new Zend_Translate_Exception($ex);

Now that worked really well. According to the Internets, I should have some "upload file" capability here. Probably it's disabled because you don't want to host random stuff?

Whatever, here's a link to the patch:

Fixed in trunk r24649 Merged to release-1.11 in r24650 ZF2 PR: