Skip to content

Older style transmission type causes an AttributeError: 'NoneType'... #9

Closed
@BuildingAtom

Description

@BuildingAtom

When using urchin to load a URDF with older-style transmission tags, Urchin crashes with:

...
  File ".../site-packages/urchin/urdf.py", line 2078, in _from_xml
    kwargs["trans_type"] = node.find("type").text
                           ^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'text'

This appears to be caused by the assumption that type must be an element, most likely based on the current ROS page, but this causes a crash for some files as the type is an attribute of the node instead (some examples can be found in this discussion regarding the transmission tag linked by that ROS page).

One possible fix for that that I'm using at the moment is to check the node attributes first. I expand and edit line 2078 of urdf.py so that the surrounding function now looks like:

    @classmethod
    def _from_xml(cls, node, path):
        kwargs = cls._parse(node, path)
        try:
            trans_type = node.attrib.get('type')
            if trans_type is None:
                trans_type = node.find("type").text
            kwargs["trans_type"] = trans_type
        except AttributeError:
            kwargs["trans_type"] = ''
        return Transmission(**kwargs)

Though, this also makes the type optional (since it seems like it might not be required anyway?).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions