From a47ed74a06271424178ff4167d4951d745af7c26 Mon Sep 17 00:00:00 2001 From: luopengting Date: Thu, 2 Apr 2020 20:56:42 +0800 Subject: [PATCH] add error code for MaxCountExceededError, change exception used in summary_watcher --- mindinsight/datavisual/common/exceptions.py | 8 ++++---- mindinsight/datavisual/data_transform/summary_watcher.py | 6 +++--- mindinsight/datavisual/utils/tools.py | 4 ++-- mindinsight/utils/constant.py | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/mindinsight/datavisual/common/exceptions.py b/mindinsight/datavisual/common/exceptions.py index d99f1fd..05fdcd6 100644 --- a/mindinsight/datavisual/common/exceptions.py +++ b/mindinsight/datavisual/common/exceptions.py @@ -83,10 +83,10 @@ class NodeNotInGraphError(MindInsightException): http_code=400) -class MaxCountExceededException(MindInsightException): +class MaxCountExceededError(MindInsightException): """Count is out of limit.""" def __init__(self): error_msg = "Count is out of limit." - super(MaxCountExceededException, self).__init__(DataVisualErrors.NODE_NOT_IN_GRAPH_ERROR, - error_msg, - http_code=400) + super(MaxCountExceededError, self).__init__(DataVisualErrors.MAX_COUNT_EXCEEDED_ERROR, + error_msg, + http_code=400) diff --git a/mindinsight/datavisual/data_transform/summary_watcher.py b/mindinsight/datavisual/data_transform/summary_watcher.py index 7d6d59f..e9680c6 100644 --- a/mindinsight/datavisual/data_transform/summary_watcher.py +++ b/mindinsight/datavisual/data_transform/summary_watcher.py @@ -22,7 +22,7 @@ from pathlib import Path from mindinsight.datavisual.common.log import logger from mindinsight.datavisual.common.validation import Validation from mindinsight.datavisual.utils.tools import Counter -from mindinsight.utils.exceptions import ParamValueError +from mindinsight.datavisual.common.exceptions import MaxCountExceededError from mindinsight.utils.exceptions import FileSystemPermissionError @@ -87,7 +87,7 @@ class SummaryWatcher: break try: counter.add() - except ParamValueError: + except MaxCountExceededError: logger.info('Stop further scanning due to overall is False and ' 'number of scanned files exceeds upper limit.') break @@ -132,7 +132,7 @@ class SummaryWatcher: break try: counter.add() - except ParamValueError: + except MaxCountExceededError: logger.info('Stop further scanning due to overall is False and ' 'number of scanned files exceeds upper limit.') break diff --git a/mindinsight/datavisual/utils/tools.py b/mindinsight/datavisual/utils/tools.py index 8333341..1b4322d 100644 --- a/mindinsight/datavisual/utils/tools.py +++ b/mindinsight/datavisual/utils/tools.py @@ -20,7 +20,7 @@ import os from numbers import Number from urllib.parse import unquote -from mindinsight.datavisual.common.exceptions import MaxCountExceededException +from mindinsight.datavisual.common.exceptions import MaxCountExceededError from mindinsight.utils import exceptions _IMG_EXT_TO_MIMETYPE = { @@ -165,5 +165,5 @@ class Counter: def add(self, value=1): """Add value.""" if self._max_count is not None and self._count + value > self._max_count: - raise MaxCountExceededException() + raise MaxCountExceededError() self._count += value diff --git a/mindinsight/utils/constant.py b/mindinsight/utils/constant.py index b9eaca9..67a2cbc 100644 --- a/mindinsight/utils/constant.py +++ b/mindinsight/utils/constant.py @@ -50,7 +50,7 @@ class DataVisualErrors(Enum): """Enum definition for datavisual errors.""" RESTFUL_API_NOT_EXIST = 1 REQUEST_METHOD_NOT_ALLOWED = 2 - SUMMARY_LOG_CONTENT_INVALID = 3 + MAX_COUNT_EXCEEDED_ERROR = 3 CRC_FAILED = 4 TRAIN_JOB_NOT_EXIST = 5 SUMMARY_LOG_PATH_INVALID = 6 -- GitLab