]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Better error reporting in virsh.
authorChris Lalancette <clalance@redhat.com>
Sat, 3 Apr 2010 01:24:50 +0000 (21:24 -0400)
committerChris Lalancette <clalance@redhat.com>
Tue, 6 Apr 2010 13:48:13 +0000 (09:48 -0400)
When hitting failures in virsh, a common idiom is
to jump to a cleanup label, free some resources, and
then return a FALSE error code to vshCommandRun.
In theory, vshCommandRun is then supposed to print
out the last error.  The problem is that many of
the cleanup paths have library calls to free resources,
and all of those library calls clear out the last error.
This is leading to situations where no error is being
reported at all.

This patch remedies the situation somewhat by
printing out the errors inside the command methods
themselves when we know it will go through a cleanup
path that will lose the error.

Signed-off-by: Chris Lalancette <clalance@redhat.com>
tools/virsh.c

index ad64bc0d181071f59dc2038be927666d72eeb447..c7551fde3a4a8b48b4a8382a7457319871041266 100644 (file)
@@ -2622,9 +2622,8 @@ cmdDomXMLFromNative(vshControl *ctl, const vshCmd *cmd)
     format = vshCommandOptString(cmd, "format", NULL);
     configFile = vshCommandOptString(cmd, "config", NULL);
 
-    if (virFileReadAll(configFile, 1024*1024, &configData) < 0) {
+    if (virFileReadAll(configFile, 1024*1024, &configData) < 0)
         return FALSE;
-    }
 
     xmlData = virConnectDomainXMLFromNative(ctl->conn, format, configData, flags);
     if (xmlData != NULL) {
@@ -2668,9 +2667,8 @@ cmdDomXMLToNative(vshControl *ctl, const vshCmd *cmd)
     format = vshCommandOptString(cmd, "format", NULL);
     xmlFile = vshCommandOptString(cmd, "xml", NULL);
 
-    if (virFileReadAll(xmlFile, 1024*1024, &xmlData) < 0) {
+    if (virFileReadAll(xmlFile, 1024*1024, &xmlData) < 0)
         return FALSE;
-    }
 
     configData = virConnectDomainXMLToNative(ctl->conn, format, xmlData, flags);
     if (configData != NULL) {
@@ -4329,9 +4327,8 @@ cmdNodeDeviceCreate(vshControl *ctl, const vshCmd *cmd)
         return FALSE;
     }
 
-    if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) {
+    if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0)
         return FALSE;
-    }
 
     dev = virNodeDeviceCreateXML(ctl->conn, buffer, 0);
     VIR_FREE(buffer);
@@ -5426,6 +5423,7 @@ cmdVolCreate(vshControl *ctl, const vshCmd *cmd)
     }
 
     if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) {
+        virshReportError(ctl);
         virStoragePoolFree(pool);
         return FALSE;
     }
@@ -5487,6 +5485,7 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd)
         goto cleanup;
 
     if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) {
+        virshReportError(ctl);
         goto cleanup;
     }
 
@@ -6927,6 +6926,7 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd)
     }
 
     if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) {
+        virshReportError(ctl);
         virDomainFree(dom);
         return FALSE;
     }
@@ -6994,6 +6994,7 @@ cmdDetachDevice(vshControl *ctl, const vshCmd *cmd)
     }
 
     if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) {
+        virshReportError(ctl);
         virDomainFree(dom);
         return FALSE;
     }
@@ -7061,6 +7062,7 @@ cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd)
     }
 
     if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) {
+        virshReportError(ctl);
         virDomainFree(dom);
         return FALSE;
     }