pleonex / atom-autocomplete-xml

Autcomplete XML package for Atom editor.
https://atom.io/packages/autocomplete-xml
MIT License
13 stars 8 forks source link

xs:annotation crashes the plugin. #9

Closed jgrodskiy-donlen closed 8 years ago

jgrodskiy-donlen commented 8 years ago

Uncaught TypeError: Cannot read property 'name' of undefined

At events.js:141

TypeError: Cannot read property 'name' of undefined
    at Object.module.exports.initTypeObject (/.atom/packages/autocomplete-xml/lib/xsdParser.coffee:110:37)
    at Object.module.exports.parseType (/.atom/packages/autocomplete-xml/lib/xsdParser.coffee:81:13)
    at Object.module.exports.parse (/.atom/packages/autocomplete-xml/lib/xsdParser.coffee:63:6)
    at /.atom/packages/autocomplete-xml/lib/xsdParser.coffee:44:45
    at Parser.<anonymous> (\.atom\packages\autocomplete-xml\node_modules\xml2js\lib\xml2js.js:483:18)
    at emitOne (events.js:77:13)
    at Parser.emit (events.js:169:7)
    at Object.onclosetag (\.atom\packages\autocomplete-xml\node_modules\xml2js\lib\xml2js.js:444:26)
    at emit (\.atom\packages\autocomplete-xml\node_modules\xml2js\node_modules\sax\lib\sax.js:639:35)
    at emitNode (\.atom\packages\autocomplete-xml\node_modules\xml2js\node_modules\sax\lib\sax.js:644:5)
    at closeTag (\.atom\packages\autocomplete-xml\node_modules\xml2js\node_modules\sax\lib\sax.js:903:7)
    at Object.write (\.atom\packages\autocomplete-xml\node_modules\xml2js\node_modules\sax\lib\sax.js:1444:13)
    at Parser.exports.Parser.Parser.parseString (\.atom\packages\autocomplete-xml\node_modules\xml2js\lib\xml2js.js:502:31)
    at Parser.bind [as parseString] (\.atom\packages\autocomplete-xml\node_modules\xml2js\lib\xml2js.js:7:59)
    at Object.exports.parseString (\.atom\packages\autocomplete-xml\node_modules\xml2js\lib\xml2js.js:534:19)
    at Object.module.exports.parseFromString (/.atom/packages/autocomplete-xml/lib/xsdParser.coffee:39:12)
    at Object.module.exports.parseFromString (\.atom\packages\autocomplete-xml\lib\xsd.coffee:50:15)
    at \.atom\packages\autocomplete-xml\lib\xsd.coffee:44:45
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)
pleonex commented 8 years ago

Thanks for reporting it. Could you add how your XSD uses xs:annotation? At the moment, the plugin expects the following format:

        <xs:annotation>
            <xs:documentation>
                Documentation here.
            </xs:documentation>
        </xs:annotation>
jgrodskiy-donlen commented 8 years ago

NP, You doing me a favor by getting this working. If i knew how to debug coffee script I'd get you more data. For now console.log does the trick.

Issue 1. If you have a large block right under schema for annotation.

<xs:annotation>
    <xs:documentation>
        Lorem ipsum dolor sit amet, consectetur adipiscing elit.
        Nulla non orci eget nunc ullamcorper venenatis.
        Proin eget dui nec velit malesuada imperdiet eget vel risus.
        Mauris elementum justo ut erat vulputate, nec molestie ante aliquam.
        Aliquam sagittis mi at ornare pharetra.
        Praesent ut erat mollis, fermentum risus nec, scelerisque nisl.

        (A) + (B) = (V) .  D

        Lorem ipsum dolor sit amet, consectetur adipiscing elit.
        Nulla non orci eget nunc ullamcorper venenatis.
        Proin eget dui nec velit malesuada imperdiet eget vel risus.
        Mauris elementum justo ut erat vulputate, nec molestie ante aliquam.
        Aliquam sagittis mi at ornare pharetra.
        Praesent ut erat mollis, fermentum risus nec, scelerisque nisl.

        Lorem ipsum dolor sit amet, consectetur adipiscing elit.
        Nulla non orci eget nunc ullamcorper venenatis.
        Proin eget dui nec velit malesuada imperdiet eget vel risus.
        Mauris elementum justo ut erat vulputate, nec molestie ante aliquam.
        Aliquam sagittis mi at ornare pharetra.
        Praesent ut erat mollis, fermentum risus nec, scelerisque nisl.
        </xs:documentation>
</xs:annotation>

Issue 2 happens with a single documentation bracket. This is dumb on our part but it does happen. `

</xsd:annotation>`

And that crashes in xsdParser.coffee @ normalizeString in the str.replace because str is a empty JS object {}.

pleonex commented 8 years ago

I think I have found the cause of the initial crash TypeError: Cannot read property 'name' of undefined. This will happen if there is a tag of any type just after the root element of the XSD without the attribute name. Does your XSD have something similar? Does it make sense? As far as I know, every complexType, simpleType, ... must contain the name attribute. In e751bce I have fixed the crash by skipping tags without the attribute.

Regarding the other issues: 1.- As you can see in this screenshot it's not crashing for me. Could the problem be related to the previous comment? large_doc

2.- Fixed in 5dad9c6, I will update the plugin soon. EDIT: 0.8.2 released.

jgrodskiy-donlen commented 8 years ago

Yes it is exactly why it is happening. We had one annotation at the root just describing the overall xsd structure.

pleonex commented 8 years ago

In that case, this should be fixed with the latest version. I am closing the issue, please reopen if it's happening again.