We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c937fd3 commit 92eee50Copy full SHA for 92eee50
packages/xml/src/xml.lib.ts
@@ -250,8 +250,15 @@ const buildXmlTree = (parts: Array<XmlPart>) => {
250
* @param content The XML like content to parse
251
* @returns The parsed XML as a tree of nodes
252
*/
253
-export const parse = <T extends Array<Xml.Node>>(content: Stringable): T =>
254
- buildXmlTree(splitXmlTags(content.toString().trim())) as T;
+export const parse = <T extends Array<Xml.Node>>(content: Stringable): T => {
+ try {
255
+ return buildXmlTree(splitXmlTags(content.toString().trim())) as T;
256
+ } catch (error) {
257
+ throw new Error(`Failed to parse XML`, {
258
+ cause: error,
259
+ });
260
+ }
261
+};
262
263
export const nodesToText = (nodes: Array<Xml.Node>) =>
264
nodes.map((n) => n.text).join("");
0 commit comments