[PATCH] esx: Improve error reporting for unknown VI types

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

 



Print the actual unknown type name instead of <other> for AnyType objects.
---
 src/esx/esx_vi.c       |    2 +-
 src/esx/esx_vi_types.c |   36 +++++++++++++++++++++++++-----------
 src/esx/esx_vi_types.h |    1 +
 3 files changed, 27 insertions(+), 12 deletions(-)

diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
index b1b5d70..9fa37e1 100644
--- a/src/esx/esx_vi.c
+++ b/src/esx/esx_vi.c
@@ -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;
     }
 
diff --git a/src/esx/esx_vi_types.c b/src/esx/esx_vi_types.c
index 9e67eff..cbc92d6 100644
--- a/src/esx/esx_vi_types.c
+++ b/src/esx/esx_vi_types.c
@@ -533,8 +533,8 @@
  * 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                                                               \
                                                                               \
@@ -543,8 +543,8 @@
                                                                               \
       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;                                                 \
     }
 
@@ -586,7 +586,9 @@
 
 #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)
 
@@ -620,14 +622,18 @@
 
 #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)
 
 
@@ -683,7 +689,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));
@@ -862,6 +868,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)
 {
@@ -869,9 +885,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;
     }
 
diff --git a/src/esx/esx_vi_types.h b/src/esx/esx_vi_types.h
index 3d843bf..d412a8f 100644
--- a/src/esx/esx_vi_types.h
+++ b/src/esx/esx_vi_types.h
@@ -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);
-- 
1.7.4.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]