xml module: Improve error message for missing namespaces

This commit is contained in:
Marko Stanković 2017-09-13 15:33:37 +02:00 committed by Dag Wieers
parent 785e604c57
commit 16ca412bd7

View file

@ -545,8 +545,11 @@ def set_target_inner(module, tree, xpath, namespaces, attribute, value):
if not is_node(tree, xpath, namespaces): if not is_node(tree, xpath, namespaces):
changed = check_or_make_target(module, tree, xpath, namespaces) changed = check_or_make_target(module, tree, xpath, namespaces)
except Exception as e: except Exception as e:
module.fail_json(msg="Xpath %s causes a failure: %s\n -- tree is %s" % missing_namespace = ""
(xpath, e, etree.tostring(tree, pretty_print=True)), exception=traceback.format_exc(e)) if len(tree.getroot().nsmap) > 0 and ":" not in xpath:
missing_namespace = "XML document has namespace(s) defined, but no namespace prefix(es) used in xpath!\n"
module.fail_json(msg="%sXpath %s causes a failure: %s\n -- tree is %s" %
(missing_namespace, xpath, e, etree.tostring(tree, pretty_print=True)), exception=traceback.format_exc())
if not is_node(tree, xpath, namespaces): if not is_node(tree, xpath, namespaces):
module.fail_json(msg="Xpath %s does not reference a node! tree is %s" % module.fail_json(msg="Xpath %s does not reference a node! tree is %s" %