Improved xml error reporting
Posted: Wed Feb 11, 2015 10:45 am
If you made a level which needed to include some templates or used lua code, you probably noticed that the xml parsing errors, especially the line where the error supposedly was, were not very useful. I set out to correct that, and it turned out to be quite easy, because lua already provides a lot of information about the code. Here are some examples how the error looks now:
If even these messages are not enough to find the mistake (or if the message is wrong), the xml data that actually gets passed along to the parser gets saved to a file.
If someone's wondering how it works:
The level files etc. actually get interpreted as lua code. Everything that is not lua code ends up inside of a print() statement, and the <?lua ?> tags get removed, producing valid lua code. The print() function is redirected to a C++ function that appends the input to a string, which in the end is the xml data to be parsed.
With that you know which line from the final xml file gets printed by which print() call. You can get information on where (file and line) the lua print() call is from inside C++ code, and thus you know where each line from the final xml data originally comes from.
It works with lua scripts that generate xml content and normal xml files. The example on the left is an example of xml generated with a lua script, but it's not very useful either way because the script writes everything to the same line. The example on the right shows a "normal" xml error, not generated with a script, but the error is in an included file.If even these messages are not enough to find the mistake (or if the message is wrong), the xml data that actually gets passed along to the parser gets saved to a file.
If someone's wondering how it works:
The level files etc. actually get interpreted as lua code. Everything that is not lua code ends up inside of a print() statement, and the <?lua ?> tags get removed, producing valid lua code. The print() function is redirected to a C++ function that appends the input to a string, which in the end is the xml data to be parsed.
With that you know which line from the final xml file gets printed by which print() call. You can get information on where (file and line) the lua print() call is from inside C++ code, and thus you know where each line from the final xml data originally comes from.