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

exceptions.py 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #
  2. # This file is part of Lodel 2 (https://github.com/OpenEdition)
  3. #
  4. # Copyright (C) 2015-2017 Cléo UMS-3287
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Affero General Public License as published
  8. # by the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Affero General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. class LodelException(Exception):
  20. pass
  21. class LodelExceptions(LodelException):
  22. ##@brief Instanciate a new exceptions handling multiple exceptions
  23. # @param msg str : Exception message
  24. # @param exceptions dict : A list of data check Exception with concerned field (or stuff) as key
  25. def __init__(self, msg = "Unknow error", exceptions = None):
  26. self._msg = msg
  27. self._exceptions = dict() if exceptions is None else exceptions
  28. def __repr__(self):
  29. return self.__str__()
  30. def __str__(self):
  31. msg = self._msg
  32. for_iter = self._exceptions.items() if isinstance(self._exceptions, dict) else enumerate(self.__exceptions)
  33. for obj, expt in for_iter:
  34. msg += "\n\t{expt_obj} : ({expt_name}) {expt_msg}; ".format(
  35. expt_obj = obj,
  36. expt_name=expt.__class__.__name__,
  37. expt_msg=str(expt)
  38. )
  39. return msg
  40. ##@brief Designed to be a non catched exception.
  41. #
  42. #@note Designed to be raised in dramatic case
  43. class LodelFatalError(Exception):
  44. pass
  45. ##@brief Designed to be a catched exception.
  46. #
  47. #@note Designed to be raised in DataHandler
  48. class DataNoneValid(Exception):
  49. pass
  50. ##@brief Designed to be a catched exception.
  51. #
  52. #@note Designed to be raised in DataHandler
  53. class FieldValidationError(Exception):
  54. pass