[Kimchi-devel] [PATCH] [Wok] Avoid log functionality to break due to missing argument

Lucio Correia posted 1 patch 7 years, 1 month ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/kimchi tags/patchew/1486746213-3794-1-git-send-email-luciojhc@linux.vnet.ibm.com
src/wok/message.py | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
[Kimchi-devel] [PATCH] [Wok] Avoid log functionality to break due to missing argument
Posted by Lucio Correia 7 years, 1 month ago
When new args are added to existing error messages, expansion of
old log entries for that message will fail due to lack of new
arg. Fix that by ignoring KeyError execptions.

Signed-off-by: Lucio Correia <luciojhc@linux.vnet.ibm.com>
---
 src/wok/message.py | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/wok/message.py b/src/wok/message.py
index ff4cbc9..f39701c 100644
--- a/src/wok/message.py
+++ b/src/wok/message.py
@@ -86,7 +86,16 @@ class WokMessage(object):
 
     def get_text(self, prepend_code=True, translate=True):
         msg = self._get_text(translate)
-        msg = decode_value(msg) % self.args
+
+        try:
+            msg = decode_value(msg) % self.args
+        except KeyError, e:
+            # When new args are added to existing log messages, old entries in
+            # log for the same message would fail due to lack of that new arg.
+            # This avoids whole log functionality to break due to that, while
+            # registers the problem.
+            msg = decode_value(msg)
+            cherrypy.log.error_log.error("KeyError: %s - %s" % (str(e), msg))
 
         if prepend_code:
             return "%s: %s" % (self.code, msg)
-- 
2.7.4

_______________________________________________
Kimchi-devel mailing list
Kimchi-devel@ovirt.org
http://lists.ovirt.org/mailman/listinfo/kimchi-devel
Re: [Kimchi-devel] [PATCH] [Wok] Avoid log functionality to break due to missing argument
Posted by Aline Manera 7 years, 1 month ago
Applied. Thanks.

Regards,

Aline Manera

_______________________________________________
Kimchi-devel mailing list
Kimchi-devel@ovirt.org
http://lists.ovirt.org/mailman/listinfo/kimchi-devel
Re: [Kimchi-devel] [PATCH] [Wok] Avoid log functionality to break due to missing argument
Posted by Ramon Medeiros 7 years, 1 month ago
Reviewed-By: Ramon Medeiros <ramonn@br.ibm.com>


On 02/10/2017 03:03 PM, Lucio Correia wrote:
> When new args are added to existing error messages, expansion of
> old log entries for that message will fail due to lack of new
> arg. Fix that by ignoring KeyError execptions.
>
> Signed-off-by: Lucio Correia <luciojhc@linux.vnet.ibm.com>
> ---
>   src/wok/message.py | 11 ++++++++++-
>   1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/src/wok/message.py b/src/wok/message.py
> index ff4cbc9..f39701c 100644
> --- a/src/wok/message.py
> +++ b/src/wok/message.py
> @@ -86,7 +86,16 @@ class WokMessage(object):
>
>       def get_text(self, prepend_code=True, translate=True):
>           msg = self._get_text(translate)
> -        msg = decode_value(msg) % self.args
> +
> +        try:
> +            msg = decode_value(msg) % self.args
> +        except KeyError, e:
> +            # When new args are added to existing log messages, old entries in
> +            # log for the same message would fail due to lack of that new arg.
> +            # This avoids whole log functionality to break due to that, while
> +            # registers the problem.
> +            msg = decode_value(msg)
> +            cherrypy.log.error_log.error("KeyError: %s - %s" % (str(e), msg))
>
>           if prepend_code:
>               return "%s: %s" % (self.code, msg)

_______________________________________________
Kimchi-devel mailing list
Kimchi-devel@ovirt.org
http://lists.ovirt.org/mailman/listinfo/kimchi-devel