dataset_checker.py 2.1 KB

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