[Kimchi-devel] [PATCHv3] Exception: fix exception details when not specified

Zhou Zheng Sheng zhshzhou at linux.vnet.ibm.com
Tue May 27 02:12:06 UTC 2014


Reviewed-by: Zhou Zheng Sheng <zhshzhou at linux.vnet.ibm.com>

Another example for a few lines of code leading to big discussion and
debug. It means code review and discussion is very useful to avoid
patch-following-patch-following-patch problem.

on 2014/05/26 18:22, lvroyce at linux.vnet.ibm.com wrote:
> From: Royce Lv <lvroyce at linux.vnet.ibm.com>
> 
> v2>v3, Because kimchi exception used unicode as msg, convert it to str
>        to make unicode encode work.
> v1>v2, Add a new type of error to cover general schema validation error.
> (per Sheldon's comments)
> 
> Not every validation error needs to translate for user,
> we define user interested errors,
> other developer interested error should report directly by schema validator,
> and handled by developer directly.
> fix exception handling for this situation.
> 
> Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
> Signed-off-by: Zheng Sheng Zhou <zhshzhou at linux.vnet.ibm.com>
> ---
>  src/kimchi/control/utils.py | 6 ++++--
>  src/kimchi/i18n.py          | 1 +
>  2 files changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/src/kimchi/control/utils.py b/src/kimchi/control/utils.py
> index 5e63816..081bb81 100644
> --- a/src/kimchi/control/utils.py
> +++ b/src/kimchi/control/utils.py
> @@ -98,8 +98,10 @@ def validate_params(params, instance, action):
>      try:
>          validator.validate(request)
>      except ValidationError, e:
> -        raise InvalidParameter(e.schema['error'], {'value': str(e.instance)})
> -
> +        if e.schema.get('error'):
> +            raise InvalidParameter(e.schema['error'], {'value': str(e.instance)})
> +        else:
> +            raise InvalidParameter("KCHAPI0008E", {"err": str(e.message)})
> 
>  class UrlSubNode(object):
> 
> diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py
> index 25b703f..4ed13fe 100644
> --- a/src/kimchi/i18n.py
> +++ b/src/kimchi/i18n.py
> @@ -30,6 +30,7 @@ messages = {
>      "KCHAPI0005E": _("Create is not allowed for %(resource)s"),
>      "KCHAPI0006E": _("Unable to parse JSON request"),
>      "KCHAPI0007E": _("This API only supports JSON"),
> +    "KCHAPI0008E": _("Parameters does not match requirement in schema: %(err)s"),
> 
>      "KCHASYNC0001E": _("Datastore is not initiated in the model object."),
>      "KCHASYNC0002E": _("Unable to start task due error: %(err)s"),
> 


-- 
Zhou Zheng Sheng / 周征晟
E-mail: zhshzhou at linux.vnet.ibm.com
Telephone: 86-10-82454397




More information about the Kimchi-devel mailing list