Skip to content

Load Blockly XML parse error causes IDE UI glitches #305

@jarmitage

Description

@jarmitage

Example of a file that fails to parse (not sure why - old Blocks?)

<xml xmlns="https://developers.google.com/blockly/xml">
    <variables>
        <variable type="">n</variable>
        <variable type="">reading</variable>
        <variable type="">Vbatt</variable>
        <variable type="">txtVbatt</variable>
    </variables>
    <block type="espruino_pinMode" x="-221" y="-137">
        <field name="MODE">input</field>
        <value name="PIN">
            <block type="espruino_pin">
                <field name="PIN">D30</field>
            </block>
        </value>
        <next>
            <block type="variables_set" inline="false">
                <field name="VAR" variabletype="">n</field>
                <value name="VALUE">
                    <block type="math_number">
                        <field name="NUM">100</field>
                    </block>
                </value>
                <next>
                    <block type="controls_repeat_ext">
                        <value name="TIMES">
                            <block type="math_number">
                                <field name="NUM">10</field>
                            </block>
                        </value>
                        <statement name="DO">
                            <block type="variables_set" inline="false">
                                <field name="VAR" variabletype="">reading</field>
                                <value name="VALUE">
                                    <block type="math_number">
                                        <field name="NUM">0</field>
                                    </block>
                                </value>
                                <next>
                                    <block type="controls_repeat_ext">
                                        <value name="TIMES">
                                            <block type="variables_get">
                                                <field name="VAR" variabletype="">n</field>
                                            </block>
                                        </value>
                                        <statement name="DO">
                                            <block type="math_change">
                                                <field name="VAR" variabletype="">reading</field>
                                                <value name="DELTA">
                                                    <block type="espruino_analogRead">
                                                        <value name="PIN">
                                                            <block type="espruino_pin">
                                                                <field name="PIN">D30</field>
                                                            </block>
                                                        </value>
                                                    </block>
                                                </value>
                                            </block>
                                        </statement>
                                        <next>
                                            <block type="variables_set" inline="false">
                                                <field name="VAR" variabletype="">Vbatt</field>
                                                <value name="VALUE">
                                                    <block type="math_arithmetic">
                                                        <field name="OP">DIVIDE</field>
                                                        <value name="A">
                                                            <block type="math_round">
                                                                <field name="OP">ROUND</field>
                                                                <value name="NUM">
                                                                    <block type="math_arithmetic">
                                                                        <field name="OP">MULTIPLY</field>
                                                                        <value name="A">
                                                                            <block type="math_number">
                                                                                <field name="NUM">10000</field>
                                                                            </block>
                                                                        </value>
                                                                        <value name="B">
                                                                            <block type="math_arithmetic">
                                                                                <field name="OP">DIVIDE</field>
                                                                                <value name="A">
                                                                                    <block type="math_arithmetic">
                                                                                        <field name="OP">MULTIPLY</field>
                                                                                        <value name="A">
                                                                                            <block type="math_number">
                                                                                                <field name="NUM">13.482</field>
                                                                                            </block>
                                                                                        </value>
                                                                                        <value name="B">
                                                                                            <block type="variables_get">
                                                                                                <field name="VAR" variabletype="">reading</field>
                                                                                            </block>
                                                                                        </value>
                                                                                    </block>
                                                                                </value>
                                                                                <value name="B">
                                                                                    <block type="variables_get">
                                                                                        <field name="VAR" variabletype="">n</field>
                                                                                    </block>
                                                                                </value>
                                                                            </block>
                                                                        </value>
                                                                    </block>
                                                                </value>
                                                            </block>
                                                        </value>
                                                        <value name="B">
                                                            <block type="math_number">
                                                                <field name="NUM">10000</field>
                                                            </block>
                                                        </value>
                                                    </block>
                                                </value>
                                                <next>
                                                    <block type="variables_set" inline="false">
                                                        <field name="VAR" variabletype="">txtVbatt</field>
                                                        <value name="VALUE">
                                                            <block type="text">
                                                                <field name="TEXT">Battery voltage: </field>
                                                            </block>
                                                        </value>
                                                        <next>
                                                            <block type="text_append" inline="false">
                                                                <field name="VAR" variabletype="">txtVbatt</field>
                                                                <value name="TEXT">
                                                                    <block type="variables_get">
                                                                        <field name="VAR" variabletype="">Vbatt</field>
                                                                    </block>
                                                                </value>
                                                                <next>
                                                                    <block type="text_append" inline="false">
                                                                        <field name="VAR" variabletype="">txtVbatt</field>
                                                                        <value name="TEXT">
                                                                            <block type="text">
                                                                                <field name="TEXT"> v</field>
                                                                            </block>
                                                                        </value>
                                                                        <next>
                                                                            <block type="text_print" inline="false">
                                                                                <value name="TEXT">
                                                                                    <block type="variables_get">
                                                                                        <field name="VAR" variabletype="">txtVbatt</field>
                                                                                    </block>
                                                                                </value>
                                                                                <next>
                                                                                    <block type="espruino_delay">
                                                                                        <value name="SECONDS">
                                                                                            <block type="math_number">
                                                                                                <field name="NUM">2</field>
                                                                                            </block>
                                                                                        </value>
                                                                                    </block>
                                                                                </next>
                                                                            </block>
                                                                        </next>
                                                                    </block>
                                                                </next>
                                                            </block>
                                                        </next>
                                                    </block>
                                                </next>
                                            </block>
                                        </next>
                                    </block>
                                </next>
                            </block>
                        </statement>
                    </block>
                </next>
            </block>
        </next>
    </block>
</xml>

Chrome Dev Console error

blockly_compressed.js:118 Uncaught (in promise) Error: DOMParser was unable to parse: 
    at Object.textToDom (blockly_compressed.js:118:414)
    at Object.setXML (index.js:104041:52)
    at setActiveFile (index.js:98940:35)
    at createNewTab (index.js:99033:5)
    at index.js:99258:22
    at Array.forEach (<anonymous>)
    at index.js:99256:21

Screenshot of IDE editor:
Image

Despite the parse error, a program tab is still created in the tab bar. Navigating to this tab shows an empty editor. It is not possible to close the tab, unless you refresh the page.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions