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

Lucio Correia posted 1 patch 4 years, 2 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/kimchi-wok tags/patchew/1486746213-3794-1-git-send-email-luciojhc@linux.vnet.ibm.com
Test Unit Tests passed
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 4 years, 2 months 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 Ramon Medeiros 4 years, 2 months 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

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

Posted by Aline Manera 4 years, 2 months ago
Applied. Thanks.

Regards,

Aline Manera

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