From 7c9a7a52660d4fb84a4ee961c358a4aa66202b81 Mon Sep 17 00:00:00 2001 From: Kamran Manzoor Date: Sun, 15 Dec 2019 20:17:08 +0100 Subject: [PATCH] Add exception handling Signed-off-by: Kamran Manzoor --- sonarcheck_analyzer.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/sonarcheck_analyzer.py b/sonarcheck_analyzer.py index 800463d..128026a 100644 --- a/sonarcheck_analyzer.py +++ b/sonarcheck_analyzer.py @@ -78,13 +78,18 @@ def notify_review_event(self, request, context): change.head.path, request.commit_revision.head.hash, e) continue + logger.debug("check_results %s", check_results) for check in check_results: for res in check_results[check]: - comments.append( - pb.Comment( - file=change.head.path, - line=(res.get("pos", {}) or {}).get("line", 0), - text="{}: {}".format(check, res["msg"]))) + try: + comments.append( + pb.Comment( + file=change.head.path, + line=(res.get("pos", {}) or {}).get("line", 0), + text="{}: {}".format(check, res["msg"]))) + except Exception as e: + logger.exception("Error occurred while creating a comment: %s", e) + continue logger.info("%d comments produced", len(comments))