[PATCH 3/5] Raise exception instead of returning None

Chris Lalancette clalancette at gmail.com
Wed Dec 14 14:31:20 UTC 2011


On Tue, Dec 13, 2011 at 11:11 AM, James Laska <jlaska at redhat.com> wrote:
> ---
>  oz/ozutil.py |    5 +++--
>  1 files changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/oz/ozutil.py b/oz/ozutil.py
> index 40932c0..727d7d2 100644
> --- a/oz/ozutil.py
> +++ b/oz/ozutil.py
> @@ -265,9 +265,10 @@ def string_to_bool(instr):
>     lower = instr.lower()
>     if lower == 'no' or lower == 'false':
>         return False
> -    if lower == 'yes' or lower == 'true':
> +    elif lower == 'yes' or lower == 'true':
>         return True
> -    return None
> +    else:
> +        raise Exception, "Unhandled input string: %s" % instr

The problem with doing this is that it makes the method less flexible,
but more crucially it makes the error messages more generic.  If you
look at all of the places in Oz that currently call string_to_bool(),
they all check for None and raise an appropriate error.  If we move it
into this function, we can remove some redundant lines of code at the
expense of precision.  I'm inclined to leave things as-is, but I could
be convinced by a good argument.

Chris



More information about the aeolus-devel mailing list