{"record":{"id":"e34c7cece526d06d","repo":"AtsushiSakai/PythonRobotics","slug":"root-name-decorator-node-must-have-exactly-one-c","errorCode":null,"errorMessage":"{root.name} Decorator node must have exactly one child","messagePattern":"(.+?) Decorator node must have exactly one child","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"MissionPlanning/BehaviorTree/behavior_tree.py","lineNumber":632,"sourceCode":"        \"\"\"\n        Build a node from an XML element.\n\n        Args:\n            node (Element): The XML element to build the node from.\n\n        Returns:\n            BehaviorTree Node: the built node\n        \"\"\"\n        if node.tag in self.node_builders:\n            root = self.node_builders[node.tag](node)\n            if root.type == NodeType.CONTROL_NODE:\n                if len(node) <= 0:\n                    raise ValueError(f\"{root.name} Control node must have children\")\n                for child in node:\n                    root.children.append(self.build_node(child))\n            elif root.type == NodeType.DECORATOR_NODE:\n                if len(node) != 1:\n                    raise ValueError(\n                        f\"{root.name} Decorator node must have exactly one child\"\n                    )\n                root.child = self.build_node(node[0])\n            elif root.type == NodeType.ACTION_NODE:\n                if len(node) != 0:\n                    raise ValueError(f\"{root.name} Action node must have no children\")\n            return root\n        else:\n            raise ValueError(f\"Unknown node type: {node.tag}\")\n\n    def build_tree(self, xml_string):\n        \"\"\"\n        Build a behavior tree from an XML string.\n\n        Args:\n            xml_string (str): The XML string containing the behavior tree.\n\n        Returns:","sourceCodeStart":614,"sourceCodeEnd":650,"githubUrl":"https://github.com/AtsushiSakai/PythonRobotics/blob/1fe4fb980f6a12fe21c3c33d2b4da97a52c9154d/MissionPlanning/BehaviorTree/behavior_tree.py#L614-L650","documentation":"Raised by build_node when a decorator-node tag in the XML does not contain exactly one child element. Decorators wrap a single node, so zero or multiple children are structural errors.","triggerScenarios":"XML like <Inverter name=\"i\"/> (zero children) or an Inverter enclosing two child tags.","commonSituations":"Nesting mistakes in hand-authored XML, or copying a control-node pattern under a decorator tag.","solutions":["Give the decorator tag exactly one child element in the XML.","Move extra children out or wrap them in a sequence under the decorator.","Lint the XML tree structure before calling build_tree."],"exampleFix":"<!-- before -->\n<Inverter name=\"i\">\n  <ActionA name=\"a\"/>\n  <ActionB name=\"b\"/>\n</Inverter>\n\n<!-- after -->\n<Inverter name=\"i\">\n  <Sequence name=\"s\">\n    <ActionA name=\"a\"/>\n    <ActionB name=\"b\"/>\n  </Sequence>\n</Inverter>","handlingStrategy":"validation","validationCode":"for el in root.iter():\n    if el.tag in DECORATOR_TAGS and len(el) != 1:\n        raise ValueError(f'{el.tag} {el.get(\"name\")} must have exactly one child')","typeGuard":null,"tryCatchPattern":"try:\n    tree = builder.build_tree(xml_string)\nexcept ValueError as e:\n    if 'exactly one child' in str(e):\n        wrap_extra_children_in_sequence(xml_string)\n    raise","preventionTips":["Author trees with a validator that enforces per-tag arity rules.","Prefer building complex structures with sequence/selector under a single decorator child."],"tags":["behavior-tree","xml-parsing","decorator-node"],"backgroundTag":"xml-schema-validation-failed","analyzedSha":"1fe4fb980f6a12fe21c3c33d2b4da97a52c9154d","analyzedAt":"2026-08-28T13:23:33.733Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}