提交 16793534 编写于 作者: M Matthias Bolte

esx: Improve error reporting for unknown VI types

Print the actual unknown type name instead of <other> for AnyType objects.
上级 ce53382b
...@@ -1481,7 +1481,7 @@ esxVI_Enumeration_CastFromAnyType(const esxVI_Enumeration *enumeration, ...@@ -1481,7 +1481,7 @@ esxVI_Enumeration_CastFromAnyType(const esxVI_Enumeration *enumeration,
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Expecting type '%s' but found '%s'"), _("Expecting type '%s' but found '%s'"),
esxVI_Type_ToString(enumeration->type), esxVI_Type_ToString(enumeration->type),
esxVI_Type_ToString(anyType->type)); esxVI_AnyType_TypeToString(anyType));
return -1; return -1;
} }
......
...@@ -533,8 +533,8 @@ ...@@ -533,8 +533,8 @@
* Macros to implement dynamic dispatched functions * Macros to implement dynamic dispatched functions
*/ */
#define ESX_VI__TEMPLATE__DISPATCH(_actual_type, __type, _dispatch, \ #define ESX_VI__TEMPLATE__DISPATCH(_actual_type, _actual_type_name, __type, \
_error_return) \ _dispatch, _error_return) \
switch (_actual_type) { \ switch (_actual_type) { \
_dispatch \ _dispatch \
\ \
...@@ -543,8 +543,8 @@ ...@@ -543,8 +543,8 @@
\ \
default: \ default: \
virReportError(VIR_ERR_INTERNAL_ERROR, \ virReportError(VIR_ERR_INTERNAL_ERROR, \
_("Call to %s for unexpected type '%s'"), __FUNCTION__,\ _("Call to %s for unexpected type '%s'"), \
esxVI_Type_ToString(_actual_type)); \ __FUNCTION__, _actual_type_name); \
return _error_return; \ return _error_return; \
} }
...@@ -586,7 +586,9 @@ ...@@ -586,7 +586,9 @@
#define ESX_VI__TEMPLATE__DYNAMIC_FREE(__type, _dispatch, _body) \ #define ESX_VI__TEMPLATE__DYNAMIC_FREE(__type, _dispatch, _body) \
ESX_VI__TEMPLATE__FREE(__type, \ 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 */) \ /* nothing */) \
_body) _body)
...@@ -620,21 +622,27 @@ ...@@ -620,21 +622,27 @@
#define ESX_VI__TEMPLATE__DYNAMIC_DEEP_COPY(__type, _dispatch, _deep_copy) \ #define ESX_VI__TEMPLATE__DYNAMIC_DEEP_COPY(__type, _dispatch, _deep_copy) \
ESX_VI__TEMPLATE__DEEP_COPY(__type, \ 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) _deep_copy)
#define ESX_VI__TEMPLATE__DYNAMIC_CAST_FROM_ANY_TYPE(__type, _dispatch) \ #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__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 */) /* nothing */)
#define ESX_VI__TEMPLATE__DYNAMIC_SERIALIZE(__type, _dispatch, _serialize) \ #define ESX_VI__TEMPLATE__DYNAMIC_SERIALIZE(__type, _dispatch, _serialize) \
ESX_VI__TEMPLATE__SERIALIZE_EXTRA(__type, \ 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) _serialize)
...@@ -690,7 +698,7 @@ esxVI_GetActualObjectType(xmlNodePtr node, esxVI_Type baseType, ...@@ -690,7 +698,7 @@ esxVI_GetActualObjectType(xmlNodePtr node, esxVI_Type baseType,
*actualType = esxVI_Type_FromString(type); *actualType = esxVI_Type_FromString(type);
if (*actualType == esxVI_Type_Undefined) { if (*actualType == esxVI_Type_Undefined || *actualType == esxVI_Type_Other) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unknown value '%s' for %s 'type' property"), _("Unknown value '%s' for %s 'type' property"),
type, esxVI_Type_ToString(baseType)); type, esxVI_Type_ToString(baseType));
...@@ -869,6 +877,16 @@ ESX_VI__TEMPLATE__FREE(AnyType, ...@@ -869,6 +877,16 @@ ESX_VI__TEMPLATE__FREE(AnyType,
VIR_FREE(item->value); 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 int
esxVI_AnyType_ExpectType(esxVI_AnyType *anyType, esxVI_Type type) esxVI_AnyType_ExpectType(esxVI_AnyType *anyType, esxVI_Type type)
{ {
...@@ -876,9 +894,7 @@ 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, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Expecting type '%s' but found '%s'"), _("Expecting type '%s' but found '%s'"),
esxVI_Type_ToString(type), esxVI_Type_ToString(type),
anyType->type != esxVI_Type_Other esxVI_AnyType_TypeToString(anyType));
? esxVI_Type_ToString(anyType->type)
: anyType->other);
return -1; return -1;
} }
......
...@@ -154,6 +154,7 @@ struct _esxVI_AnyType { ...@@ -154,6 +154,7 @@ struct _esxVI_AnyType {
int esxVI_AnyType_Alloc(esxVI_AnyType **anyType); int esxVI_AnyType_Alloc(esxVI_AnyType **anyType);
void esxVI_AnyType_Free(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_ExpectType(esxVI_AnyType *anyType, esxVI_Type type);
int esxVI_AnyType_DeepCopy(esxVI_AnyType **dest, esxVI_AnyType *src); int esxVI_AnyType_DeepCopy(esxVI_AnyType **dest, esxVI_AnyType *src);
int esxVI_AnyType_Deserialize(xmlNodePtr node, esxVI_AnyType **anyType); int esxVI_AnyType_Deserialize(xmlNodePtr node, esxVI_AnyType **anyType);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册