From: Viliam Luc Date: Mon, 17 Jan 2022 09:45:15 +0000 (+0100) Subject: trending: shorten error messages X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=commitdiff_plain;h=b022196c957892cc5748cf6fa688776be81a7219 trending: shorten error messages Sometimes error messages are longer than 1000 chars. This change looks for [;, :, '] in messages between 128 and 256 character. If it finds any of these the error message will be cut from beggining to this character. If there's no character from the list in error message and message is longer than 128 chars. It will be cut from beggining to 129 character of error message Signed-off-by: Viliam Luc Change-Id: I283f8ee8d81422235d897370dbc9508fafda6a7f --- diff --git a/resources/tools/presentation/generator_alerts.py b/resources/tools/presentation/generator_alerts.py index d22e7aa963..c3bf81d7ff 100644 --- a/resources/tools/presentation/generator_alerts.py +++ b/resources/tools/presentation/generator_alerts.py @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Cisco and/or its affiliates. +# Copyright (c) 2022 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -279,6 +279,38 @@ class Alerting: line, error_msg = line[:-1].split(u'###', maxsplit=1) test = line.split(u'-') name = u'-'.join(test[3:-1]) + if len(error_msg) > 128: + if u";" in error_msg[128:256]: + error_msg = \ + f"{error_msg[:128]}" \ + f"{error_msg[128:].split(u';', 1)[0]}..." + elif u":" in error_msg[128:256]: + error_msg = \ + f"{error_msg[:128]}" \ + f"{error_msg[128:].split(u':', 1)[0]}..." + elif u"." in error_msg[128:256]: + error_msg = \ + f"{error_msg[:128]}" \ + f"{error_msg[128:].split(u'.', 1)[0]}..." + elif u"?" in error_msg[128:256]: + error_msg = \ + f"{error_msg[:128]}" \ + f"{error_msg[128:].split(u'?', 1)[0]}..." + elif u"!" in error_msg[128:256]: + error_msg = \ + f"{error_msg[:128]}" \ + f"{error_msg[128:].split(u'!', 1)[0]}..." + elif u"," in error_msg[128:256]: + error_msg = \ + f"{error_msg[:128]}" \ + f"{error_msg[128:].split(u',', 1)[0]}..." + elif u" " in error_msg[128:256]: + error_msg = \ + f"{error_msg[:128]}" \ + f"{error_msg[128:].split(u' ', 1)[0]}..." + else: + error_msg = error_msg[:128] + except ValueError: continue