qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH 2/8] qapi script: report error for default case


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH 2/8] qapi script: report error for default case in union visit
Date: Tue, 12 Nov 2013 09:51:01 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0

On 11/06/2013 12:33 PM, Wenchao Xia wrote:
> It is possible to reach default case, when an union have a enum
> discriminator, so don't abort() but report the error message.
> 
> Signed-off-by: Wenchao Xia <address@hidden>
> ---
>  scripts/qapi-visit.py |   14 ++++++++++++--
>  1 files changed, 12 insertions(+), 2 deletions(-)

I still think this is not ideal.  You are proposing a runtime error:

> +    # Tell caller the value is invalid, since the discriminator value maybe 
> an
> +    # unmapped enum value.
>      ret += mcgen('''
>              default:
> -                abort();
> +                error_setg(&err,
> +                           "Invalid discriminator value %(pi)s for %(name)s",
> +                           (*obj)->kind);
> +                break;
>              }

whereas I'm requesting a compile-time error - it is much easier for
maintenance reasons to have the generator require up-front that all enum
values are covered, and loudly complain if an enum type is extended
without also extending the use of that enum type in a union, than it is
to silently generate a runtime error and wait for the bug reports
several weeks down the road.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]