From aa78a8b56686459096723dfe736af18448fab45b Mon Sep 17 00:00:00 2001 From: Andrew n marshall Date: Tue, 14 Nov 2017 13:36:38 -0800 Subject: [PATCH] Better error reporting when the test XML fails to load. (#1443) --- tests/generators/index.html | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/generators/index.html b/tests/generators/index.html index ab5a593b6..0239b67e1 100644 --- a/tests/generators/index.html +++ b/tests/generators/index.html @@ -100,7 +100,7 @@ function loadXml() { } var xmlText = fetchFile(url); if (xmlText !== null) { - fromXml(xmlText); + fromXml(url, xmlText); } } @@ -124,7 +124,11 @@ function fetchFile(xmlUrl) { return xmlHttp.responseText; } -function fromXml(xmlText) { +/** + * @param {string} filename The URL (or other name) of the XML, for reporting. + * @param {string} xmlText The actual XML text. + */ +function fromXml(filename, xmlText) { var output = document.getElementById('importExport'); output.value = xmlText; output.scrollTop = 0; @@ -132,11 +136,16 @@ function fromXml(xmlText) { demoWorkspace.clear(); try { var xmlDoc = Blockly.Xml.textToDom(xmlText); + Blockly.Xml.domToWorkspace(xmlDoc, demoWorkspace); } catch (e) { - alert('Error parsing XML:\n' + e); + var msg = 'Error parsing XML: ' + filename + '\n\n\t' + e; + if (e.stack) { + msg += '\n\nSee console for stack trace details.' + } + console.error(e.stack ? e : msg); + alert(msg); return; } - Blockly.Xml.domToWorkspace(xmlDoc, demoWorkspace); } function setOutput(text) {