From 2d68ab4aebb36f84846cbffce5483d771ef7a2c8 Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Wed, 2 May 2018 21:53:39 -0400 Subject: [PATCH] Propagate Parser Errors Perhaps we can implement a full linter using a proper error handler at some point. For now, I just want it to be clear when the tree can't be rendered due to an invalid XML document. --- src/tree-view/xml-tree-data-provider.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/tree-view/xml-tree-data-provider.ts b/src/tree-view/xml-tree-data-provider.ts index 1cce499..f79205e 100644 --- a/src/tree-view/xml-tree-data-provider.ts +++ b/src/tree-view/xml-tree-data-provider.ts @@ -215,7 +215,11 @@ export class XmlTreeDataProvider implements TreeDataProvider { const xml = this.activeEditor.document.getText(); try { - this._xmlDocument = new DOMParser().parseFromString(xml, "text/xml"); + this._xmlDocument = new DOMParser({ + errorHandler: () => { + throw new Error("Invalid Document"); + } + }).parseFromString(xml, "text/xml"); } catch {