Problem
ALOY-250 solved the issue of malformed XML and making it abort Alloy compilation. Unfortunately it required a hack-ish workaround to a shortcoming in the xmldom module. Specifically, xmldom only reports a message via
console.warn
when it encounters malformed XML. It does not abort the parsing, which results in tough-to-debug, unexpected behavior for developers. To remedy, when executing
new DOMParser().parseFromString
in Alloy, we override
console.warn
before the call to make it abort the app if encountered, and then set
console.warn
back to normal afterwards. here's the snippet:
var warn = console.warn;
console.warn = function(msg) {
exports.die(['Error parsing XML document', msg]);
};
var doc = new DOMParser().parseFromString(string);
console.warn = warn;
Obviously this type of hack should ideally be avoided. it would also be nice if we could get more information other than just the tag names of the XML involved, like perhaps line numbers. In any case, this needs to be revisited and improved.
* The hack alternatives
** An issue has been logged for error reporting. Ideally this will be implemented by the owner, but the repository doesn't exactly see a lot of activity.
** fork and modify ourselves and maintain a alloy-specific version of xmldom
** Looks for other xml alternatives, like jsdom (see also, time-consuming)
Update (9/14/2012)
My original logged issue has not yet been commented on:
https://github.com/jindw/xmldom/issues/36
but the apparently work is underway:
https://github.com/jindw/xmldom/commit/eb17b3af06eae4d7d29c5debe74780e347deb0b3
Will watch progress and keep an eye out for new published version to npm.
Increased the priority as it turns out some of the bad xmldom error reporting, or lack thereof, can cause freezes in the alloy process. Not ending in error, but instead chewing up resources until it is manually aborted.
Got a few other devs to test more complex apps and all looks good with the xml parsing and new error output.