]> xenbits.xensource.com Git - libvirt.git/commitdiff
esx: Improve error reporting for unknown VI types
authorMatthias Bolte <matthias.bolte@googlemail.com>
Sat, 21 Jul 2012 20:50:24 +0000 (22:50 +0200)
committerMatthias Bolte <matthias.bolte@googlemail.com>
Sun, 29 Jul 2012 05:32:25 +0000 (07:32 +0200)
Print the actual unknown type name instead of <other> for AnyType objects.

src/esx/esx_vi.c
src/esx/esx_vi_types.c
src/esx/esx_vi_types.h

index ab79afe94bd57436e30f1a12d25a90b9c2675769..2c789e1d9d5fc8c29b21f9d93004ed05f1fb9cc2 100644 (file)
@@ -1481,7 +1481,7 @@ esxVI_Enumeration_CastFromAnyType(const esxVI_Enumeration *enumeration,
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Expecting type '%s' but found '%s'"),
                        esxVI_Type_ToString(enumeration->type),
-                       esxVI_Type_ToString(anyType->type));
+                       esxVI_AnyType_TypeToString(anyType));
         return -1;
     }
 
index a0efb68fcd367839844bcefe8827b4c91a076a42..708aedabddcd7a3fa35426fb1f075cf4dbeb353f 100644 (file)
  * Macros to implement dynamic dispatched functions
  */
 
-#define ESX_VI__TEMPLATE__DISPATCH(_actual_type, __type, _dispatch,           \
-                                   _error_return)                             \
+#define ESX_VI__TEMPLATE__DISPATCH(_actual_type, _actual_type_name, __type,   \
+                                   _dispatch,  _error_return)                 \
     switch (_actual_type) {                                                   \
       _dispatch                                                               \
                                                                               \
                                                                               \
       default:                                                                \
         virReportError(VIR_ERR_INTERNAL_ERROR,                                \
-                       _("Call to %s for unexpected type '%s'"), __FUNCTION__,\
-                       esxVI_Type_ToString(_actual_type));                    \
+                       _("Call to %s for unexpected type '%s'"),              \
+                       __FUNCTION__, _actual_type_name);                      \
         return _error_return;                                                 \
     }
 
 
 #define ESX_VI__TEMPLATE__DYNAMIC_FREE(__type, _dispatch, _body)              \
     ESX_VI__TEMPLATE__FREE(__type,                                            \
-      ESX_VI__TEMPLATE__DISPATCH(item->_type, __type, _dispatch,              \
+      ESX_VI__TEMPLATE__DISPATCH(item->_type,                                 \
+                                 esxVI_Type_ToString(item->_type),            \
+                                 __type, _dispatch,                           \
                                  /* nothing */)                               \
       _body)
 
 
 #define ESX_VI__TEMPLATE__DYNAMIC_DEEP_COPY(__type, _dispatch, _deep_copy)    \
     ESX_VI__TEMPLATE__DEEP_COPY(__type,                                       \
-      ESX_VI__TEMPLATE__DISPATCH(src->_type, __type, _dispatch, -1)           \
+      ESX_VI__TEMPLATE__DISPATCH(src->_type,                                  \
+                                 esxVI_Type_ToString(src->_type),             \
+                                 __type, _dispatch, -1)                       \
       _deep_copy)
 
 
 
 #define ESX_VI__TEMPLATE__DYNAMIC_CAST_FROM_ANY_TYPE(__type, _dispatch)       \
     ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE_EXTRA(__type, esxVI_##__type,        \
-      ESX_VI__TEMPLATE__DISPATCH(anyType->type, __type, _dispatch, -1),       \
+      ESX_VI__TEMPLATE__DISPATCH(anyType->type,                               \
+                                 esxVI_AnyType_TypeToString(anyType),         \
+                                __type, _dispatch, -1),                       \
       /* nothing */)
 
 
 
 #define ESX_VI__TEMPLATE__DYNAMIC_SERIALIZE(__type, _dispatch, _serialize)    \
     ESX_VI__TEMPLATE__SERIALIZE_EXTRA(__type,                                 \
-      ESX_VI__TEMPLATE__DISPATCH(item->_type, __type, _dispatch, -1),         \
+      ESX_VI__TEMPLATE__DISPATCH(item->_type,                                 \
+                                 esxVI_Type_ToString(item->_type),            \
+                                 __type, _dispatch, -1),                      \
       _serialize)
 
 
@@ -690,7 +698,7 @@ esxVI_GetActualObjectType(xmlNodePtr node, esxVI_Type baseType,
 
     *actualType = esxVI_Type_FromString(type);
 
-    if (*actualType == esxVI_Type_Undefined) {
+    if (*actualType == esxVI_Type_Undefined || *actualType == esxVI_Type_Other) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Unknown value '%s' for %s 'type' property"),
                        type, esxVI_Type_ToString(baseType));
@@ -869,6 +877,16 @@ ESX_VI__TEMPLATE__FREE(AnyType,
     VIR_FREE(item->value);
 })
 
+const char *
+esxVI_AnyType_TypeToString(esxVI_AnyType *anyType)
+{
+    if (anyType->type == esxVI_Type_Other) {
+        return anyType->other;
+    } else {
+        return esxVI_Type_ToString(anyType->type);
+    }
+}
+
 int
 esxVI_AnyType_ExpectType(esxVI_AnyType *anyType, esxVI_Type type)
 {
@@ -876,9 +894,7 @@ esxVI_AnyType_ExpectType(esxVI_AnyType *anyType, esxVI_Type type)
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Expecting type '%s' but found '%s'"),
                        esxVI_Type_ToString(type),
-                       anyType->type != esxVI_Type_Other
-                       ? esxVI_Type_ToString(anyType->type)
-                       : anyType->other);
+                       esxVI_AnyType_TypeToString(anyType));
         return -1;
     }
 
index 00546d9ff4e5544a8b2a0d4be88b36528e7b4e6e..dbcfee08bb08477d63258f21055694213f232257 100644 (file)
@@ -154,6 +154,7 @@ struct _esxVI_AnyType {
 
 int esxVI_AnyType_Alloc(esxVI_AnyType **anyType);
 void esxVI_AnyType_Free(esxVI_AnyType **anyType);
+const char *esxVI_AnyType_TypeToString(esxVI_AnyType *anyType);
 int esxVI_AnyType_ExpectType(esxVI_AnyType *anyType, esxVI_Type type);
 int esxVI_AnyType_DeepCopy(esxVI_AnyType **dest, esxVI_AnyType *src);
 int esxVI_AnyType_Deserialize(xmlNodePtr node, esxVI_AnyType **anyType);