From 1307c65d74fc9a1241f0a50142921cadac1e882b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= Date: Thu, 20 Nov 2014 13:57:46 +0100 Subject: [PATCH] proper error reporting from libxml2 Change-Id: Ia173f7f4c88c90b6d54c9a47d6ae18b933502678 --- sax/source/fastparser/fastparser.cxx | 40 +++++----------------------- 1 file changed, 7 insertions(+), 33 deletions(-) diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx index e1d22d215f78..bf3aa01456d0 100644 --- a/sax/source/fastparser/fastparser.cxx +++ b/sax/source/fastparser/fastparser.cxx @@ -532,46 +532,20 @@ Event& Entity::getEvent( CallbackType aType ) return rEvent; } -OUString lclGetErrorMessage( xmlParserCtxtPtr, const OUString& sSystemId, sal_Int32 nLine ) +OUString lclGetErrorMessage( xmlParserCtxtPtr ctxt, const OUString& sSystemId, sal_Int32 nLine ) { - const sal_Char* pMessage = ""; -#if 0 - pMessage = "Error"; - switch( xmlE ) - { - case XML_ERROR_NONE: pMessage = "No"; break; - case XML_ERROR_NO_MEMORY: pMessage = "no memory"; break; - case XML_ERROR_SYNTAX: pMessage = "syntax"; break; - case XML_ERROR_NO_ELEMENTS: pMessage = "no elements"; break; - case XML_ERROR_INVALID_TOKEN: pMessage = "invalid token"; break; - case XML_ERROR_UNCLOSED_TOKEN: pMessage = "unclosed token"; break; - case XML_ERROR_PARTIAL_CHAR: pMessage = "partial char"; break; - case XML_ERROR_TAG_MISMATCH: pMessage = "tag mismatch"; break; - case XML_ERROR_DUPLICATE_ATTRIBUTE: pMessage = "duplicate attribute"; break; - case XML_ERROR_JUNK_AFTER_DOC_ELEMENT: pMessage = "junk after doc element"; break; - case XML_ERROR_PARAM_ENTITY_REF: pMessage = "parameter entity reference"; break; - case XML_ERROR_UNDEFINED_ENTITY: pMessage = "undefined entity"; break; - case XML_ERROR_RECURSIVE_ENTITY_REF: pMessage = "recursive entity reference"; break; - case XML_ERROR_ASYNC_ENTITY: pMessage = "async entity"; break; - case XML_ERROR_BAD_CHAR_REF: pMessage = "bad char reference"; break; - case XML_ERROR_BINARY_ENTITY_REF: pMessage = "binary entity reference"; break; - case XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF: pMessage = "attribute external entity reference"; break; - case XML_ERROR_MISPLACED_XML_PI: pMessage = "misplaced xml processing instruction"; break; - case XML_ERROR_UNKNOWN_ENCODING: pMessage = "unknown encoding"; break; - case XML_ERROR_INCORRECT_ENCODING: pMessage = "incorrect encoding"; break; - case XML_ERROR_UNCLOSED_CDATA_SECTION: pMessage = "unclosed cdata section"; break; - case XML_ERROR_EXTERNAL_ENTITY_HANDLING: pMessage = "external entity reference"; break; - case XML_ERROR_NOT_STANDALONE: pMessage = "not standalone"; break; - default:; - } -#endif + const sal_Char* pMessage; + xmlErrorPtr error = xmlCtxtGetLastError( ctxt ); + if( error && error->message ) + pMessage = error->message; + else + pMessage = "unknown error"; OUStringBuffer aBuffer( '[' ); aBuffer.append( sSystemId ); aBuffer.append( " line " ); aBuffer.append( nLine ); aBuffer.append( "]: " ); aBuffer.appendAscii( pMessage ); - aBuffer.append( " error" ); return aBuffer.makeStringAndClear(); }