From: <vac...@us...> - 2010-04-10 08:40:05
|
Revision: 181 http://xmlwrapp.svn.sourceforge.net/xmlwrapp/?rev=181&view=rev Author: vaclavslavik Date: 2010-04-10 08:39:59 +0000 (Sat, 10 Apr 2010) Log Message: ----------- Better error reporting when input file doesn't exist. Previously, tree_parser would return a generic "unknown XML parsing error" message if it failed because the specific XML file didn't exist or otherwise couldn't be read. We now treat this all too common special case specially and emit clear diagnostics. Modified Paths: -------------- trunk/NEWS trunk/src/libxml/tree_parser.cxx trunk/tests/tree/test_tree.cxx Modified: trunk/NEWS =================================================================== --- trunk/NEWS 2010-04-10 08:39:38 UTC (rev 180) +++ trunk/NEWS 2010-04-10 08:39:59 UTC (rev 181) @@ -10,6 +10,8 @@ Added xml::node::clear() method. + Better error reporting when xml::tree_parser input file doesn't exist. + Version 0.6.2 Fixed xml::tree_parser to fail on non-fatal parser errors. Modified: trunk/src/libxml/tree_parser.cxx =================================================================== --- trunk/src/libxml/tree_parser.cxx 2010-04-10 08:39:38 UTC (rev 180) +++ trunk/src/libxml/tree_parser.cxx 2010-04-10 08:39:59 UTC (rev 181) @@ -45,6 +45,7 @@ // standard includes #include <stdexcept> #include <cstring> +#include <cstdio> #include <string> #include <memory> @@ -156,6 +157,25 @@ } else { + if ( pimpl_->last_error_ == DEFAULT_ERROR ) + { + // Try to describe the problem better. A common issue is that + // a file couldn't be found, in which case "unknown XML parsing + // error" is more than unhelpful. + FILE *test = fopen(name, "r"); + if ( !test ) + { + pimpl_->last_error_ = "failed to open file \""; + pimpl_->last_error_ += name; + pimpl_->last_error_ += "\""; + } + else + { + // no such luck, the error is something else + fclose(test); + } + } + // a problem appeared if (tmpdoc) xmlFreeDoc(tmpdoc); Modified: trunk/tests/tree/test_tree.cxx =================================================================== --- trunk/tests/tree/test_tree.cxx 2010-04-10 08:39:38 UTC (rev 180) +++ trunk/tests/tree/test_tree.cxx 2010-04-10 08:39:59 UTC (rev 181) @@ -144,6 +144,8 @@ BOOST_AUTO_TEST_CASE( nonexistent_file ) { xml::tree_parser parser("doesnt_exist.xml", false); + BOOST_CHECK_EQUAL( parser.get_error_message(), + "failed to open file \"doesnt_exist.xml\"" ); BOOST_CHECK( !parser ); // failed } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |