Skip to content
This repository has been archived by the owner on Aug 5, 2022. It is now read-only.

Commit

Permalink
Print the file line and column number context in libxml2 error messages
Browse files Browse the repository at this point in the history
This used to be done by libxml2 itself when using the "generic error handler"
but was lost when switching to the "structured error handler".

Unfortunately, we do not have as much context as with the generic handler,
which used to also print the incriminated content and point to the exact
location of the error. I didn't find any easy way to get it.

Signed-off-by: David Wagner <[email protected]>
  • Loading branch information
dawagner committed Oct 20, 2015
1 parent d1c6bf3 commit 1015c96
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion xmlserializer/XmlSerializingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,10 @@ void CXmlSerializingContext::appendLineToError(const std::string& strAppend)
void CXmlSerializingContext::structuredErrorHandler(void* userData, xmlErrorPtr error)
{
CXmlSerializingContext *self = static_cast<CXmlSerializingContext *>(userData);
self->_strXmlError += error->message;

std::string filename = (error->file != NULL) ? error->file : "(user input)";
// xmlErrorPtr->int2 contains the column; see xmlerror.h
self->_strXmlError += filename + ":" +
std::to_string(error->line) + ":" + std::to_string(error->int2) + ": " +
error->message;
}

0 comments on commit 1015c96

Please sign in to comment.