dataset_checker.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # copyright (c) 2024 PaddlePaddle Authors. All Rights Reserve.
  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. __all__ = [
  15. 'FailedError', 'CheckFailedError', 'ConvertFailedError', 'SplitFailedError',
  16. 'AnalyseFailedError', 'CheckFailedError', 'DatasetFileNotFoundError'
  17. ]
  18. class FailedError(Exception):
  19. """ base error class """
  20. def __init__(self, err_info=None, solution=None, message=None):
  21. if message is None:
  22. message = self._construct_message(err_info, solution)
  23. super().__init__(message)
  24. def _construct_message(self, err_info, solution):
  25. if err_info is None:
  26. return ""
  27. else:
  28. msg = f"{self.mode} failed. We encountered the following error:\n {err_info}"
  29. if solution is not None:
  30. msg += f"\nPlease try to resolve the issue as follows:\n {solution}"
  31. return msg
  32. class CheckFailedError(FailedError):
  33. """ check dataset error """
  34. mode = "Check dataset"
  35. class ConvertFailedError(FailedError):
  36. """ convert dataset error """
  37. mode = "Convert dataset"
  38. class SplitFailedError(FailedError):
  39. """ split dataset error """
  40. mode = "Split dataset"
  41. class AnalyseFailedError(FailedError):
  42. """ analyse dataset error """
  43. mode = "Analyse dataset"
  44. class DatasetFileNotFoundError(CheckFailedError):
  45. """ dataset file not found error """
  46. def __init__(self,
  47. file_path=None,
  48. err_info=None,
  49. solution=None,
  50. message=None):
  51. if err_info is None:
  52. if file_path is not None:
  53. err_info = f"{file_path} does not exist."
  54. super().__init__(err_info, solution, message)