You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

exceptions.py 9.3 kB

5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. # Copyright 2019 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ============================================================================
  15. """Define custom exception."""
  16. from mindinsight.utils.constant import DataVisualErrors
  17. from mindinsight.utils.exceptions import MindInsightException
  18. class RestfulApiNotExist(MindInsightException):
  19. """404 not found."""
  20. def __init__(self):
  21. error_msg = '404 Not Found.'
  22. super(RestfulApiNotExist, self).__init__(DataVisualErrors.RESTFUL_API_NOT_EXIST,
  23. error_msg,
  24. http_code=404)
  25. class RequestMethodNotAllowed(MindInsightException):
  26. """Request method not allowed."""
  27. def __init__(self):
  28. error_msg = '405 Method Not Allowed.'
  29. super(RequestMethodNotAllowed, self).__init__(DataVisualErrors.REQUEST_METHOD_NOT_ALLOWED,
  30. error_msg,
  31. http_code=405)
  32. class PathNotDirectoryError(MindInsightException):
  33. """Raised when specified path do not exist."""
  34. def __init__(self, error_detail):
  35. """Initialize PathNotExistError"""
  36. error_msg = 'Specified path is not a directory. Detail: {}'.format(error_detail)
  37. super(PathNotDirectoryError, self).__init__(DataVisualErrors.PATH_NOT_DIRECTORY_ERROR,
  38. error_msg,
  39. http_code=400)
  40. class SummaryLogPathInvalid(MindInsightException):
  41. """No valid log file in the path."""
  42. def __init__(self):
  43. error_msg = 'No valid summary log file in path'
  44. super(SummaryLogPathInvalid, self).__init__(DataVisualErrors.SUMMARY_LOG_PATH_INVALID,
  45. error_msg,
  46. http_code=400)
  47. class CRCFailedError(MindInsightException):
  48. """CRC fail, record corrupted."""
  49. def __init__(self):
  50. error_msg = 'CRC Failed.'
  51. super(CRCFailedError, self).__init__(DataVisualErrors.CRC_FAILED,
  52. error_msg,
  53. http_code=400)
  54. class SummaryLogIsLoading(MindInsightException):
  55. """Data is loading."""
  56. def __init__(self, error_detail):
  57. error_msg = "Data is loading. Detail: %s" % error_detail
  58. super(SummaryLogIsLoading, self).__init__(DataVisualErrors.SUMMARY_LOG_IS_LOADING,
  59. error_msg,
  60. http_code=400)
  61. class NodeNotInGraphError(MindInsightException):
  62. """Can not find node in graph error."""
  63. def __init__(self, node_name, node_type=None):
  64. if node_type is not None:
  65. error_msg = f"Can not find node in graph by the given node name. node name: {node_name}, type: {node_type}."
  66. else:
  67. error_msg = f"Can not find node in graph by the given node name. node name: {node_name}."
  68. super(NodeNotInGraphError, self).__init__(DataVisualErrors.NODE_NOT_IN_GRAPH_ERROR,
  69. error_msg,
  70. http_code=400)
  71. class MaxCountExceededError(MindInsightException):
  72. """Count is out of limit."""
  73. def __init__(self):
  74. error_msg = "Count is out of limit."
  75. super(MaxCountExceededError, self).__init__(DataVisualErrors.MAX_COUNT_EXCEEDED_ERROR,
  76. error_msg,
  77. http_code=400)
  78. class TrainJobNotExistError(MindInsightException):
  79. """Can not find the given train job."""
  80. def __init__(self, error_detail=None):
  81. if error_detail is None:
  82. error_msg = f"Train job is not exist."
  83. else:
  84. error_msg = f"Train job is not exist. Detail: {error_detail}"
  85. super(TrainJobNotExistError, self).__init__(DataVisualErrors.TRAIN_JOB_NOT_EXIST,
  86. error_msg,
  87. http_code=400)
  88. class QueryStringContainsNullByteError(MindInsightException):
  89. """Query string contains null byte error."""
  90. def __init__(self, error_detail):
  91. error_msg = f"Query string contains null byte error. Detail: {error_detail}"
  92. super(QueryStringContainsNullByteError, self).__init__(DataVisualErrors.QUERY_STRING_CONTAINS_NULL_BYTE,
  93. error_msg,
  94. http_code=400)
  95. class PluginNotAvailableError(MindInsightException):
  96. """The given plugin is not available."""
  97. def __init__(self, error_detail):
  98. error_msg = f"Plugin is not available. Detail: {error_detail}"
  99. super(PluginNotAvailableError, self).__init__(DataVisualErrors.PLUGIN_NOT_AVAILABLE,
  100. error_msg,
  101. http_code=400)
  102. class GraphNotExistError(MindInsightException):
  103. """Can not found the given graph."""
  104. def __init__(self, error_detail=None):
  105. error_msg = 'Graph is not exist.' if error_detail is None else f'Graph is not exist. Detail: {error_detail}'
  106. super(GraphNotExistError, self).__init__(DataVisualErrors.GRAPH_NOT_EXIST,
  107. error_msg,
  108. http_code=400)
  109. class ImageNotExistError(MindInsightException):
  110. """Unable to get a image based on a given condition."""
  111. def __init__(self, error_detail):
  112. error_msg = f'Image is not exist. Detail: {error_detail}'
  113. super(ImageNotExistError, self).__init__(DataVisualErrors.IMAGE_NOT_EXIST,
  114. error_msg,
  115. http_code=400)
  116. class ScalarNotExistError(MindInsightException):
  117. """Unable to get scalar values based on a given condition."""
  118. def __init__(self, error_detail):
  119. error_msg = f'Scalar value is not exist. Detail: {error_detail}'
  120. super(ScalarNotExistError, self).__init__(DataVisualErrors.SCALAR_NOT_EXIST,
  121. error_msg,
  122. http_code=400)
  123. class HistogramNotExistError(MindInsightException):
  124. """Unable to get histogram values based on a given condition."""
  125. def __init__(self, error_detail):
  126. error_msg = f'Histogram value is not exist. Detail: {error_detail}'
  127. super(HistogramNotExistError, self).__init__(DataVisualErrors.HISTOGRAM_NOT_EXIST,
  128. error_msg,
  129. http_code=400)
  130. class TensorNotExistError(MindInsightException):
  131. """Unable to get tensor values based on a given condition."""
  132. def __init__(self, error_detail):
  133. error_msg = f'Tensor value is not exist. Detail: {error_detail}'
  134. super(TensorNotExistError, self).__init__(DataVisualErrors.TENSOR_NOT_EXIST,
  135. error_msg,
  136. http_code=400)
  137. class StepTensorDataNotInCacheError(MindInsightException):
  138. """Tensor data with specific step does not in cache."""
  139. def __init__(self, error_detail):
  140. error_msg = f'Tensor data not in cache. Detail: {error_detail}'
  141. super(StepTensorDataNotInCacheError, self).__init__(DataVisualErrors.STEP_TENSOR_DATA_NOT_IN_CACHE,
  142. error_msg,
  143. http_code=400)
  144. class ResponseDataExceedMaxValueError(MindInsightException):
  145. """Response data exceed max value based on a given condition."""
  146. def __init__(self, error_detail):
  147. error_msg = f'Response data exceed max value. Detail: {error_detail}'
  148. super(ResponseDataExceedMaxValueError, self).__init__(DataVisualErrors.MAX_RESPONSE_DATA_EXCEEDED_ERROR,
  149. error_msg,
  150. http_code=400)
  151. class TrainJobDetailNotInCacheError(MindInsightException):
  152. """Detail info of given train job is not in cache."""
  153. def __init__(self, error_detail="no detail provided."):
  154. error_msg = f'Detail info of the given train job is not in cache. Detail: {error_detail}'
  155. super().__init__(DataVisualErrors.TRAIN_JOB_DETAIL_NOT_IN_CACHE,
  156. error_msg,
  157. http_code=400)