[libvirt] [PATCH v2 01/14] util: add a virReportEnumRangeError for bad value reporting

John Ferlan jferlan at redhat.com
Tue Feb 20 18:42:54 UTC 2018



On 02/20/2018 12:08 PM, Daniel P. Berrangé wrote:
> To ensure we have standardized error messages when reporting problems
> with enum values being out of a range, add virReportEnumRangeError().
> 
>    virReportEnumRangeError(virDomainState, 34);
> 
> results in a message
> 
>    "internal error: Unexpected enum value 34 for virDomainState"
> 
> Signed-off-by: Daniel P. Berrangé <berrange at redhat.com>
> ---
>  src/util/virerror.h | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/src/util/virerror.h b/src/util/virerror.h
> index cf434f45fc..1d02451604 100644
> --- a/src/util/virerror.h
> +++ b/src/util/virerror.h
> @@ -164,7 +164,14 @@ void virReportSystemErrorFull(int domcode,
>  # define virReportRestrictedError(...) \
>      virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_OPERATION_DENIED, \
>                           __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
> -
> +/* The sizeof(typname) comparison here is a hack to catch typos
> + * in the name of the enum by triggering a compile error. It should
> + * get optimized away since sizeof() is known at compile time  */
> +# define virReportEnumRangeError(typname, value) \
> +    virReportErrorHelper(VIR_FROM_THIS, VIR_ERR_INTERNAL_ERROR, \
> +                         __FILE__, __FUNCTION__, __LINE__,      \
> +                         "Unexpected enum value %d for %s",     \

Need to resolve syntax-check warning about right-aligned "\"...

> +                         value, sizeof(typname) != 0 ? #typname : #typname);

I saw some internal IRC over the sizeof check... Assuming Eric and you
come up with something reasonable...

Reviewed-by: John Ferlan <jferlan at redhat.com>

John

Even though I'm not 100% on board with the whole error message for LAST
and default especially when they're a cannot get there...

>  
>  void virReportOOMErrorFull(int domcode,
>                             const char *filename,
> 




More information about the libvir-list mailing list