-
Notifications
You must be signed in to change notification settings - Fork 137
fix: wrap error from fast-xml-parser when invalid xml parsed #518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/resolve/sourceComponent.ts
Outdated
try { | ||
return this.parse<T>(contents); | ||
} catch (e) { | ||
// only attempt validating once there's an error to avoid the performance hit of validating every file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
src/resolve/sourceComponent.ts
Outdated
return this.parse<T>(contents); | ||
} catch (e) { | ||
// only attempt validating once there's an error to avoid the performance hit of validating every file | ||
const validation = validate(contents); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think having them both use a sharedprivate parseAndValidateXML()
would be more DRY.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had that for a while - but it was causing testing issues because parse
was stubbed, but I got it working 👍
QA notes this was pretty hard to QA (SDR doesn't care about most xml or parse it on a source:convert or deploy, including apexClasses or object/field stuff). my VSCode had an xml extension that would remove stuff inside a self-closing tag. I finally got the new, improved error to happen via <?xml version="1.0" encoding="UTF-8"?>
<CustomLabels xmlns="http://soap.sforce.com/2006/04/metadata">
<labels>
<fullName>force_app_Label_1</fullName>
<language>en_US</language>
<protected>true</protected>
<shortDescription>force-app Label 1</shortDescription>
<value>force-app</value>
</labels>
<CustomLabels>
<SelfClos ✅ resulted in ../../plugin-source/bin/run force:source:convert -d force-app --outputdir mdapiOut
ERROR running force:source:convert: Component conversion failed: error parsing /Users/shane.mclaughlin/eng/repros/mdapiDeployReport/force-app/main/default/labels/CustomLabels.labels-meta.xml due to:
message: Invalid '[ "CustomLabels", "CustomLabels", "SelfClos"]' found.
line: 1
code: InvalidXml which is way better than the original error. It's still possibly to convert/deploy a lot of invalid xml (well, the metadata API throws the errors back). 🤷🏻♂️ It only throws the error on the first failure--you can't get all the xml errors in your project |
What does this PR do?
when the
fast-xml-parser
library throws an error due to invalid xml, we will parse that error, and add the file that caused the error.given a custom labels xml file
note the opening CustomLabels tag is actually a closing tag
What issues does this PR fix or reference?
#1261, @W-10119453@
Functionality Before
TypeError: Cannot read property 'addChild' of undefined
Functionality After