From 28aeae03d0253151a21f71936d296b9eaaa8ce73 Mon Sep 17 00:00:00 2001 From: luopengting Date: Thu, 16 Apr 2020 16:12:47 +0800 Subject: [PATCH] catch DecodeError in proto decode, enhance sorting when TypeError --- mindinsight/lineagemgr/querier/querier.py | 20 +++++++++++++------ .../summary/lineage_summary_analyzer.py | 3 ++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/mindinsight/lineagemgr/querier/querier.py b/mindinsight/lineagemgr/querier/querier.py index 2f87981..4dc1560 100644 --- a/mindinsight/lineagemgr/querier/querier.py +++ b/mindinsight/lineagemgr/querier/querier.py @@ -105,10 +105,14 @@ class ExpressionType(enum.Enum): cls.LE.value, cls.GE.value]: return False - if except_key == cls.IN.value: - state = operator.contains(except_value, actual_value) - else: - state = getattr(operator, except_key)(actual_value, except_value) + try: + if except_key == cls.IN.value: + state = operator.contains(except_value, actual_value) + else: + state = getattr(operator, except_key)(actual_value, except_value) + except TypeError: + # actual_value can not compare with except_value + return False return state @@ -280,8 +284,12 @@ class Querier: elif value2 is None: cmp_result = 1 else: - cmp_result = (value1 > value2) - (value1 < value2) - + try: + cmp_result = (value1 > value2) - (value1 < value2) + except TypeError: + type1 = str(type(value1)) + type2 = str(type(value2)) + cmp_result = (type1 > type2) - (type1 < type2) return cmp_result self._parse_fail_summary_logs() diff --git a/mindinsight/lineagemgr/summary/lineage_summary_analyzer.py b/mindinsight/lineagemgr/summary/lineage_summary_analyzer.py index 9f9ad25..ff76b79 100644 --- a/mindinsight/lineagemgr/summary/lineage_summary_analyzer.py +++ b/mindinsight/lineagemgr/summary/lineage_summary_analyzer.py @@ -18,6 +18,7 @@ from collections import namedtuple from enum import Enum from google.protobuf.json_format import MessageToDict +from google.protobuf.message import DecodeError from mindinsight.datavisual.proto_files.mindinsight_lineage_pb2 import LineageEvent from mindinsight.datavisual.utils import crc32 @@ -202,7 +203,7 @@ class LineageSummaryAnalyzer(SummaryAnalyzer): analyzer = cls(file_path) try: lineage_info = analyzer.get_latest_info() - except (MindInsightException, IOError) as err: + except (MindInsightException, IOError, DecodeError) as err: log.error("Failed to get lineage information.") log.exception(err) raise LineageSummaryAnalyzeException() -- GitLab