[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 3/4] Improve incorrect root element error messages



---
 src/conf/cpu_conf.c           |    7 ++++---
 src/conf/domain_conf.c        |   21 ++++++++++++++-------
 src/conf/interface_conf.c     |    6 ++++--
 src/conf/network_conf.c       |    6 ++++--
 src/conf/node_device_conf.c   |    6 ++++--
 src/conf/nwfilter_conf.c      |    2 +-
 src/conf/secret_conf.c        |    6 ++++--
 src/conf/storage_conf.c       |   12 ++++++++----
 src/security/virt-aa-helper.c |    3 ++-
 src/test/test_driver.c        |   13 ++++++++++---
 src/util/xml.c                |    2 +-
 11 files changed, 56 insertions(+), 28 deletions(-)

diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c
index db8b4bb..9ea11cb 100644
--- a/src/conf/cpu_conf.c
+++ b/src/conf/cpu_conf.c
@@ -118,9 +118,10 @@ virCPUDefParseXML(const xmlNodePtr node,
     unsigned int i;
 
     if (!xmlStrEqual(node->name, BAD_CAST "cpu")) {
-        virCPUReportError(VIR_ERR_INTERNAL_ERROR,
-                          "%s",
-                          _("XML does not contain expected 'cpu' element"));
+        virCPUReportError(VIR_ERR_XML_CONFIG,
+                          _("unexpected root element <%s> "
+                            "expecting to see <cpu>"),
+                          node->name);
         return NULL;
     }
 
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 7fba385..ac3d955 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -4867,7 +4867,7 @@ virDomainDeviceDefPtr virDomainDeviceDefParse(virCapsPtr caps,
 
     node = xmlDocGetRootElement(xml);
     if (node == NULL) {
-        virDomainReportError(VIR_ERR_XML_ERROR,
+        virDomainReportError(VIR_ERR_XML_CONFIG,
                              "%s", _("missing root element"));
         goto error;
     }
@@ -6322,8 +6322,10 @@ virDomainDefPtr virDomainDefParseNode(virCapsPtr caps,
     virDomainDefPtr def = NULL;
 
     if (!xmlStrEqual(root->name, BAD_CAST "domain")) {
-        virDomainReportError(VIR_ERR_INTERNAL_ERROR,
-                              "%s", _("incorrect root element"));
+        virDomainReportError(VIR_ERR_XML_CONFIG,
+                             _("unexpected root element <%s>, "
+                               "expecting to see <domain>"),
+                             root->name);
         goto cleanup;
     }
 
@@ -6351,8 +6353,10 @@ virDomainObjParseNode(virCapsPtr caps,
     virDomainObjPtr obj = NULL;
 
     if (!xmlStrEqual(root->name, BAD_CAST "domstatus")) {
-        virDomainReportError(VIR_ERR_INTERNAL_ERROR,
-                             "%s", _("incorrect root element"));
+        virDomainReportError(VIR_ERR_XML_CONFIG,
+                             _("unexpected root element <%s>, "
+                               "expecting to see <domstatus>"),
+                             root->name);
         goto cleanup;
     }
 
@@ -9015,13 +9019,16 @@ virDomainSnapshotDefPtr virDomainSnapshotDefParseString(const char *xmlStr,
     }
 
     if ((root = xmlDocGetRootElement(xml)) == NULL) {
-        virDomainReportError(VIR_ERR_INTERNAL_ERROR,
+        virDomainReportError(VIR_ERR_XML_CONFIG,
                               "%s", _("missing root element"));
         goto cleanup;
     }
 
     if (!xmlStrEqual(root->name, BAD_CAST "domainsnapshot")) {
-        virDomainReportError(VIR_ERR_XML_ERROR, "%s", _("domainsnapshot"));
+        virDomainReportError(VIR_ERR_XML_CONFIG,
+                             _("unexpected root element <%s> "
+                               "expecting to see <domainsnapshot>"),
+                             root->name);
         goto cleanup;
     }
 
diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c
index 37b9c7c..c07ffc8 100644
--- a/src/conf/interface_conf.c
+++ b/src/conf/interface_conf.c
@@ -831,8 +831,10 @@ virInterfaceDefPtr virInterfaceDefParseNode(xmlDocPtr xml,
     virInterfaceDefPtr def = NULL;
 
     if (!xmlStrEqual(root->name, BAD_CAST "interface")) {
-        virInterfaceReportError(VIR_ERR_INTERNAL_ERROR,
-                              "%s", _("incorrect root element"));
+        virInterfaceReportError(VIR_ERR_XML_CONFIG,
+                                _("unexpected root element <%s>, "
+                                  "expecting to see <interface>"),
+                                root->name);
         return NULL;
     }
 
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 7ab2352..88848ee 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -728,8 +728,10 @@ virNetworkDefPtr virNetworkDefParseNode(xmlDocPtr xml,
     virNetworkDefPtr def = NULL;
 
     if (!xmlStrEqual(root->name, BAD_CAST "network")) {
-        virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
-                              "%s", _("incorrect root element"));
+        virNetworkReportError(VIR_ERR_XML_CONFIG,
+                              _("unexpected root element <%s>, "
+                                "expecting to see <network>"),
+                              root->name);
         return NULL;
     }
 
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index cc28b2a..8e7c573 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -1205,8 +1205,10 @@ virNodeDeviceDefParseNode(xmlDocPtr xml,
     virNodeDeviceDefPtr def = NULL;
 
     if (!xmlStrEqual(root->name, BAD_CAST "device")) {
-        virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR,
-                                 "%s", _("incorrect root element"));
+        virNodeDeviceReportError(VIR_ERR_XML_CONFIG,
+                                 _("unexpected root element <%s>, "
+                                   "expecting to see <device>"),
+                                 root->name);
         return NULL;
     }
 
diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c
index 368aca0..0aee8a4 100644
--- a/src/conf/nwfilter_conf.c
+++ b/src/conf/nwfilter_conf.c
@@ -2152,7 +2152,7 @@ virNWFilterDefParse(virConnectPtr conn,
 
     node = xmlDocGetRootElement(xml);
     if (node == NULL) {
-        virNWFilterReportError(VIR_ERR_XML_ERROR,
+        virNWFilterReportError(VIR_ERR_XML_CONFIG,
                                "%s", _("missing root element"));
         goto cleanup;
     }
diff --git a/src/conf/secret_conf.c b/src/conf/secret_conf.c
index 30f1a3d..37a513b 100644
--- a/src/conf/secret_conf.c
+++ b/src/conf/secret_conf.c
@@ -112,8 +112,10 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root)
     char *uuidstr = NULL;
 
     if (!xmlStrEqual(root->name, BAD_CAST "secret")) {
-        virSecretReportError(VIR_ERR_XML_ERROR, "%s",
-                             _("incorrect root element"));
+        virSecretReportError(VIR_ERR_XML_CONFIG,
+                             _("unexpected root element <%s>, "
+                               "expecting to see <secret>"),
+                             root->name);
         goto cleanup;
     }
 
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 9ccff15..76ea103 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -750,8 +750,10 @@ virStoragePoolDefParseNode(xmlDocPtr xml,
     virStoragePoolDefPtr def = NULL;
 
     if (STRNEQ((const char *)root->name, "pool")) {
-        virStorageReportError(VIR_ERR_XML_ERROR,
-                              "%s", _("unknown root element for storage pool"));
+        virStorageReportError(VIR_ERR_XML_CONFIG,
+                              _("unexpected root element <%s> "
+                                "expecting to see <pool>"),
+                              root->name);
         goto cleanup;
     }
 
@@ -1130,8 +1132,10 @@ virStorageVolDefParseNode(virStoragePoolDefPtr pool,
     virStorageVolDefPtr def = NULL;
 
     if (STRNEQ((const char *)root->name, "volume")) {
-        virStorageReportError(VIR_ERR_XML_ERROR,
-                          "%s", _("unknown root element for storage vol"));
+        virStorageReportError(VIR_ERR_XML_CONFIG,
+                              _("unexpected root element <%s> "
+                                "expecting to see <volume>"),
+                              root->name);
         goto cleanup;
     }
 
diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c
index 08ff53c..0b24516 100644
--- a/src/security/virt-aa-helper.c
+++ b/src/security/virt-aa-helper.c
@@ -684,7 +684,8 @@ caps_mockup(vahControl * ctl, const char *xmlStr)
     }
 
     if (!xmlStrEqual(root->name, BAD_CAST "domain")) {
-        vah_error(NULL, 0, _("incorrect root element"));
+        vah_error(NULL, 0, _("unexpected root element <%s>, expecting to see "
+                             "<domain>"), root->name));
         goto cleanup;
     }
 
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 0978214..6a6f189 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -798,9 +798,16 @@ static int testOpenFromFile(virConnectPtr conn,
     VIR_FORCE_CLOSE(fd);
 
     root = xmlDocGetRootElement(xml);
-    if ((root == NULL) || (!xmlStrEqual(root->name, BAD_CAST "node"))) {
-        testError(VIR_ERR_XML_ERROR, "%s",
-                  _("Root element is not 'node'"));
+    if (root == NULL) {
+        testError(VIR_ERR_XML_CONFIG, "%s",
+                  _("missing root element"));
+        goto error;
+    }
+    if (!xmlStrEqual(root->name, BAD_CAST "node")) {
+        testError(VIR_ERR_XML_CONFIG,
+                  _("unexpected root element <%s> "
+                    "expecting to see <node>"),
+                  root->name);
         goto error;
     }
 
diff --git a/src/util/xml.c b/src/util/xml.c
index d2989e2..2ad21cd 100644
--- a/src/util/xml.c
+++ b/src/util/xml.c
@@ -696,7 +696,7 @@ virXMLParseHelper(int domcode,
         goto error;
 
     if (xmlDocGetRootElement(xml) == NULL) {
-        virGenericReportError(domcode, VIR_ERR_INTERNAL_ERROR,
+        virGenericReportError(domcode, VIR_ERR_XML_CONFIG,
                               "%s", _("missing root element"));
         goto error;
     }
-- 
1.7.4.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]