]> xenbits.xensource.com Git - libvirt.git/commitdiff
xen: add error handling to UUID parsing
authorGuido Günther <agx@sigxcpu.org>
Thu, 6 Oct 2011 10:42:39 +0000 (12:42 +0200)
committerGuido Günther <agx@sigxcpu.org>
Mon, 10 Oct 2011 20:57:41 +0000 (22:57 +0200)
otherwise a missing UUID in a domain config just shows:

error: An error occurred, but the cause is unknown

Now we have:

error: configuration file syntax error: config value uuid was missing

src/xenxs/xen_xm.c

index 70facf78d9b0c08421a38508e8ca4c14d49ac139..ff173d8de3bae95542fe8b06a87551348f90922e 100644 (file)
@@ -174,21 +174,38 @@ static int xenXMConfigCopyStringOpt(virConfPtr conf,
 /* Convenience method to grab a string UUID from the config file object */
 static int xenXMConfigGetUUID(virConfPtr conf, const char *name, unsigned char *uuid) {
     virConfValuePtr val;
-    if (!uuid || !name || !conf)
-        return (-1);
+
+    if (!uuid || !name || !conf) {
+        XENXS_ERROR(VIR_ERR_INVALID_ARG,
+                   _("Arguments must be non null"));
+        return -1;
+    }
+
     if (!(val = virConfGetValue(conf, name))) {
-        return (-1);
+        XENXS_ERROR(VIR_ERR_CONF_SYNTAX,
+                   _("config value %s was missing"), name);
+        return -1;
     }
 
-    if (val->type != VIR_CONF_STRING)
-        return (-1);
-    if (!val->str)
-        return (-1);
+    if (val->type != VIR_CONF_STRING) {
+        XENXS_ERROR(VIR_ERR_CONF_SYNTAX,
+                   _("config value %s not a string"), name);
+        return -1;
+    }
+
+    if (!val->str) {
+        XENXS_ERROR(VIR_ERR_CONF_SYNTAX,
+                   _("%s can't be empty"), name);
+        return -1;
+    }
 
-    if (virUUIDParse(val->str, uuid) < 0)
-        return (-1);
+    if (virUUIDParse(val->str, uuid) < 0) {
+        XENXS_ERROR(VIR_ERR_CONF_SYNTAX,
+                   _("%s not parseable"), val->str);
+        return -1;
+    }
 
-    return (0);
+    return 0;
 }
 
 #define MAX_VFB 1024