[libvirt] [PATCH] conf: Improve incorrect root element error messages

When user pass wrong root element, it is not 'internal error' and we can give him hint what we are expecting. --- src/conf/domain_conf.c | 12 ++++++++---- src/conf/interface_conf.c | 6 ++++-- src/conf/network_conf.c | 6 ++++-- src/conf/node_device_conf.c | 6 ++++-- src/conf/secret_conf.c | 6 ++++-- src/security/virt-aa-helper.c | 2 +- 6 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f04e477..bb504f9 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7932,8 +7932,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_ERROR, + _("unexpected root element <%s>, " + "expecting <domain>"), + root->name); goto cleanup; } @@ -7963,8 +7965,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_ERROR, + _("unexpected root element <%s>, " + "expecting <domstatus>"), + root->name); goto cleanup; } diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c index fd8d1ae..59f74a1 100644 --- a/src/conf/interface_conf.c +++ b/src/conf/interface_conf.c @@ -838,8 +838,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_ERROR, + _("unexpected root element <%s>, " + "expecting <interface>"), + root->name); return NULL; } diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 10afcde..1058b07 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -1107,8 +1107,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_ERROR, + _("unexpected root element <%s>, " + "expecting <network>"), + root->name); return NULL; } diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index fc284e0..084121f 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -1204,8 +1204,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_ERROR, + _("unexpected root element <%s> " + "expecting <device>"), + root->name); return NULL; } diff --git a/src/conf/secret_conf.c b/src/conf/secret_conf.c index a51fc69..6e80733 100644 --- a/src/conf/secret_conf.c +++ b/src/conf/secret_conf.c @@ -126,8 +126,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_ERROR, + _("unexpected root element <%s>, " + "expecting <secret>"), + root->name); goto cleanup; } diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index ad06974..14399cc 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -644,7 +644,7 @@ caps_mockup(vahControl * ctl, const char *xmlStr) } if (!xmlStrEqual(ctxt->node->name, BAD_CAST "domain")) { - vah_error(NULL, 0, _("incorrect root element")); + vah_error(NULL, 0, _("unexpected root element, expecting <domain>")); goto cleanup; } -- 1.7.3.4

On 11/25/2011 07:50 AM, Michal Privoznik wrote:
When user pass wrong root element, it is not 'internal error' and we can give him hint what we are expecting. --- src/conf/domain_conf.c | 12 ++++++++---- src/conf/interface_conf.c | 6 ++++-- src/conf/network_conf.c | 6 ++++-- src/conf/node_device_conf.c | 6 ++++-- src/conf/secret_conf.c | 6 ++++-- src/security/virt-aa-helper.c | 2 +- 6 files changed, 25 insertions(+), 13 deletions(-)
ACK.

On 28.11.2011 16:06, Laine Stump wrote:
On 11/25/2011 07:50 AM, Michal Privoznik wrote:
When user pass wrong root element, it is not 'internal error' and we can give him hint what we are expecting. --- src/conf/domain_conf.c | 12 ++++++++---- src/conf/interface_conf.c | 6 ++++-- src/conf/network_conf.c | 6 ++++-- src/conf/node_device_conf.c | 6 ++++-- src/conf/secret_conf.c | 6 ++++-- src/security/virt-aa-helper.c | 2 +- 6 files changed, 25 insertions(+), 13 deletions(-)
ACK.
Thanks, pushed. Michal

On 28.11.2011 16:06, Laine Stump wrote:
On 11/25/2011 07:50 AM, Michal Privoznik wrote:
When user pass wrong root element, it is not 'internal error' and we can give him hint what we are expecting. --- src/conf/domain_conf.c | 12 ++++++++---- src/conf/interface_conf.c | 6 ++++-- src/conf/network_conf.c | 6 ++++-- src/conf/node_device_conf.c | 6 ++++-- src/conf/secret_conf.c | 6 ++++-- src/security/virt-aa-helper.c | 2 +- 6 files changed, 25 insertions(+), 13 deletions(-)
ACK.
Thanks, pushed. Michal

On 11/25/2011 05:50 AM, Michal Privoznik wrote:
When user pass wrong root element, it is not 'internal error' and we can give him hint what we are expecting. --- src/conf/domain_conf.c | 12 ++++++++---- src/conf/interface_conf.c | 6 ++++-- src/conf/network_conf.c | 6 ++++-- src/conf/node_device_conf.c | 6 ++++-- src/conf/secret_conf.c | 6 ++++-- src/security/virt-aa-helper.c | 2 +- 6 files changed, 25 insertions(+), 13 deletions(-)
Overall, a nice improvement.
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f04e477..bb504f9 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7932,8 +7932,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_ERROR, + _("unexpected root element <%s>, " + "expecting <domain>"), + root->name); goto cleanup; }
But while most hunks list the user's incorrect element,
+++ b/src/security/virt-aa-helper.c @@ -644,7 +644,7 @@ caps_mockup(vahControl * ctl, const char *xmlStr) }
if (!xmlStrEqual(ctxt->node->name, BAD_CAST "domain")) { - vah_error(NULL, 0, _("incorrect root element")); + vah_error(NULL, 0, _("unexpected root element, expecting <domain>"));
this one does not. ACK with virt-aa-helper fixed to be like the others. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 11/28/2011 08:49 AM, Eric Blake wrote:
+++ b/src/security/virt-aa-helper.c @@ -644,7 +644,7 @@ caps_mockup(vahControl * ctl, const char *xmlStr) }
if (!xmlStrEqual(ctxt->node->name, BAD_CAST "domain")) { - vah_error(NULL, 0, _("incorrect root element")); + vah_error(NULL, 0, _("unexpected root element, expecting <domain>"));
this one does not.
ACK with virt-aa-helper fixed to be like the others.
It turns out the problem here is that vah_error is hard-coded to taking one string argument, instead of being a var-args like most other error reporting methods. We should fix that, as a separate patch. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (3)
-
Eric Blake
-
Laine Stump
-
Michal Privoznik