fix: show actual parse error for malformed XML instead of generic fallback#134
Open
kyuchia wants to merge 1 commit into
Open
fix: show actual parse error for malformed XML instead of generic fallback#134kyuchia wants to merge 1 commit into
kyuchia wants to merge 1 commit into
Conversation
…lback Use DOMParser to check XML well-formedness before innerHTML insertion. Related: #133
yinanazhou
reviewed
Apr 24, 2026
Comment on lines
+90
to
+97
| // Check if user's MEI input is well-formed XML before inserting | ||
| const wrappedValue = `<root>${value}</root>`; | ||
| const userDoc = parser.parseFromString(wrappedValue, 'text/xml'); | ||
| const parseError = userDoc.querySelector('parsererror'); | ||
| if (parseError) { | ||
| resolve([parseError.textContent || 'Malformed XML']); | ||
| return; | ||
| } |
Member
There was a problem hiding this comment.
This feels redundant. We are only validating small chunks of MEI. Making L126 more specific, like indicating it's syntax error, should be enough.
Author
There was a problem hiding this comment.
Thanks for the review. I tested e.message from the innerHTML SyntaxError, it always gives the same generic message regardless of the error type:
// All three produce the exact same e.message:
try { layer.innerHTML = '<neume><nc tilt="e"/></neume'; } catch (e) { console.log(e.message); }
try { layer.innerHTML = '<neume><nc tilt="e"/></neme>'; } catch (e) { console.log(e.message); }
try { layer.innerHTML = '<neume><nc tilt="e"/><neume>'; } catch (e) { console.log(e.message); }
// "Failed to set the 'innerHTML' property on 'Element': The provided markup is invalid XML..."
So the catch block alone can't provide specific errors, which is why I added the DOMParser check before the innerHTML call. I used DOMParser because the tooltip is the only feedback users get, and I thought showing the actual parse error (like 'tag mismatch at line 3') would help users fix their input faster.
Happy to simplify if that's too much detail.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, entering malformed XML in the
meicolumn (e.g.</neumemissing>) would show a generic"Failed to validate MEI"tooltip for every error. The actual xmllint error never reached the UI.Root cause
validateMEI()inserts the user's MEI string into an XML document vialayer.innerHTML = value. On malformed XML, this throws aSyntaxErrorwhich is silently caught, and the generic fallback message is returned. The validation worker is never invoked.Fix
Added a DOMParser well-formedness check before the
innerHTMLinsertion. Malformed XML is caught early and the actual parse error is shown in the tooltip. Well-formed XML continues through the existing worker + xmllint pipeline unchanged.Before / After
Before: every malformed XML error shows the same generic message
After: tooltip shows the actual parse error
Testing
<neume>instead of</neume>) → tag mismatch error in tooltipRelated: #133