DotJoshJohnson / vscode-xml

XML Tools for Visual Studio Code
MIT License
322 stars 86 forks source link

XML Formatter Fails: `RangeError: Invalid count value` #257

Closed jiyuhan closed 5 years ago

jiyuhan commented 5 years ago

Description

When I was formatting an xml using ALT + SHIFT + F, it stops responding. Nothing, no errors being thrown out as a pop-up.

Screenshots VS Code Output - Extension Host

2019-01-21 14:17:19.085] [exthost] [error] RangeError: Invalid count value
    at String.repeat (native)
    at V2XmlFormatter._getIndent (C:\Users\thomashan\.vscode\extensions\dotjoshjohnson.xml-2.4.0\out\formatting\formatters\v2-xml-formatter.js:206:106)
    at V2XmlFormatter.formatXml (C:\Users\thomashan\.vscode\extensions\dotjoshjohnson.xml-2.4.0\out\formatting\formatters\v2-xml-formatter.js:167:39)
    at XmlFormattingEditProvider.provideDocumentRangeFormattingEdits (C:\Users\thomashan\.vscode\extensions\dotjoshjohnson.xml-2.4.0\out\formatting\xml-formatting-edit-provider.js:39:41)
    at XmlFormattingEditProvider.provideDocumentFormattingEdits (C:\Users\thomashan\.vscode\extensions\dotjoshjohnson.xml-2.4.0\out\formatting\xml-formatting-edit-provider.js:12:21)
    at c:\Users\thomashan\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:557:303
    at t.asThenable (c:\Users\thomashan\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:141:941)
    at new module.exports.t.exports (C:\Users\thomashan\.vscode\extensions\vscjava.vscode-maven-0.13.0\dist\extension.js:126:25764)
    at Object.t.asThenable (c:\Users\thomashan\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:141:909)
    at e.provideDocumentFormattingEdits (c:\Users\thomashan\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:557:262)
    at c:\Users\thomashan\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:572:705
    at e._withAdapter (c:\Users\thomashan\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:567:513)
    at e.$provideDocumentFormattingEdits (c:\Users\thomashan\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:572:667)
    at t._doInvokeHandler (c:\Users\thomashan\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:658:837)
    at t._invokeHandler (c:\Users\thomashan\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:658:509)
    at t._receiveRequest (c:\Users\thomashan\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:657:60)
    at t._receiveOneMessage (c:\Users\thomashan\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:656:59)
    at c:\Users\thomashan\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:653:895
    at c:\Users\thomashan\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:130:793
    at e.fire (c:\Users\thomashan\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:133:218)
    at a (c:\Users\thomashan\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:186:147)
    at Socket.n._socketDataListener (c:\Users\thomashan\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\node\extensionHostProcess.js:186:368)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at Socket.Readable.push (_stream_readable.js:208:10)
    at Pipe.onread (net.js:594:20)

Extension Version v2.4.0 I believe

VS Code Version 1.30.2

Operating System Windows 10

Additional Information

file name: Spring.Data.xml file length: 10922 lines

jiyuhan commented 5 years ago

@lostintangent @rdoubleui @line-o @waderyan can someone take a look at this issue? It seems very consistent, and it crashes the whole plugin.

DotJoshJohnson commented 5 years ago

Can you share what your editor.tabSize setting is?

DotJoshJohnson commented 5 years ago

Assuming the tabSize setting is a valid positive integer, there may be some invalid or otherwise unexpected syntax in the XML file causing the indentLevel to fall below 0. Here is the line throwing the error:

return ((options.editorOptions.insertSpaces) ? " ".repeat(options.editorOptions.tabSize) : "\t").repeat(indentLevel);

If you can share a copy of the XML being formatted, I can probably narrow it down to what the formatter is choking on. I should have time later this evening to take a look.

jiyuhan commented 5 years ago

@DotJoshJohnson Do you have an email I can send the file to? It's a pretty big file.

starquake commented 5 years ago

I had the same issue. Here's an example that triggers this:

<?xml version="1.0" encoding="UTF-8"?>
<test1>
    TEST <test2>aaa</test2>
</test1>

or a more realistic example:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" encoding="UTF-8" indent="yes" />

    <xsl:template match="/">
        <file>
            <xsl:apply-templates />
        </file>
    </xsl:template>

    <xsl:template match="*">
        <xsl:message terminate="no">
            WARNING: Unmatched element: <xsl:value-of select="name()"/>
        </xsl:message>
        <xsl:apply-templates/>
    </xsl:template>

</xsl:stylesheet>
stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

jiyuhan commented 5 years ago

Is there anyone working on this issue?

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 5 years ago

This issue is being automatically closed because it has not had recent activity. Thank you for your contributions.

siirila commented 5 years ago

Has there been any investigation in to this issue? Since this one was automatically closed by a bot should a new issue be opened instead? There is a very simple example of how to reproduce this issue in comment https://github.com/DotJoshJohnson/vscode-xml/issues/257#issuecomment-462768486.

brainwipe commented 5 years ago

I've just had this too; going to uninstall.

erikhoggard commented 5 years ago

I'm still seeing this error.

drmax24 commented 5 years ago

Come on. Please fix it

Version 1.34.0 (1.34.0) mac os

Drewbie18 commented 5 years ago

I am seeing this issue as well. VS Code - 1.34.0 Win 10 Pro

vojd11 commented 4 years ago

Same error, different traceback

    at String.repeat (<anonymous>)
    at V2XmlFormatter._getIndent (/home/vojd/.vscode-oss/extensions/dotjoshjohnson.xml-2.5.0/out/formatting/formatters/v2-xml-formatter.js:208:106)
    at V2XmlFormatter.formatXml (/home/vojd/.vscode-oss/extensions/dotjoshjohnson.xml-2.5.0/out/formatting/formatters/v2-xml-formatter.js:169:39)
    at XmlFormattingEditProvider.provideDocumentRangeFormattingEdits (/home/vojd/.vscode-oss/extensions/dotjoshjohnson.xml-2.5.0/out/formatting/xml-formatting-edit-provider.js:39:41)
    at XmlFormattingEditProvider.provideDocumentFormattingEdits (/home/vojd/.vscode-oss/extensions/dotjoshjohnson.xml-2.5.0/out/formatting/xml-formatting-edit-provider.js:12:21)
    at define.provideDocumentFormattingEdits.o.asPromise (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:555:286)
    at t.asPromise.Promise (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:55:720)
    at new Promise (<anonymous>)
    at Object.t.asPromise (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:55:692)
    at P.provideDocumentFormattingEdits (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:555:257)
    at define.$provideDocumentFormattingEdits._withAdapter.e (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:570:430)
    at W._withAdapter (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:565:723)
    at W.$provideDocumentFormattingEdits (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:570:408)
    at d._doInvokeHandler (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:623:396)
    at d._invokeHandler (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:623:88)
    at d._receiveRequest (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:621:730)
    at d._receiveOneMessage (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:620:605)
    at define.constructor._protocol.onMessage.e (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:618:791)
    at u.fire (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:50:207)
    at v.fire (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:186:579)
    at i.constructor.e.onMessage.e (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:783:484)
    at u.fire (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:50:207)
    at v.fire (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:186:579)
    at x._receiveMessage (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:191:17)
    at define.constructor._socketDisposables.push._socketReader.onMessage.e (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:188:116)
    at u.fire (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:50:207)
    at f.acceptChunk (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:184:17)
    at define.constructor._register._socket.onData.e (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:183:372)
    at Socket.t (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:192:491)
    at Socket.emit (events.js:182:13)
    at addChunk (_stream_readable.js:283:12)
    at readableAddChunk (_stream_readable.js:264:11)
    at Socket.Readable.push (_stream_readable.js:219:10)
    at Pipe.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)

vscode, about:

Version: 1.38.1
Commit: b37e54c98e1a74ba89e03073e5a3761284e3ffb0
Date: 2019-09-16T10:22:16.623Z
Electron: 4.2.11
Chrome: 69.0.3497.128
Node.js: 10.11.0
V8: 6.9.427.31-electron.0
OS: Linux x64 4.19.79-1-MANJARO

uname -a Linux vojd-pc 4.19.79-1-MANJARO #1 SMP PREEMPT Fri Oct 11 19:57:09 UTC 2019 x86_64 GNU/Linux

mazunind commented 4 years ago

Just had this too. Nothing helps

lc-4918 commented 4 years ago

uninstalling DotJoshJohnson formatter

louwers commented 4 years ago

Same problem here. Please re-open.