exceptions.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import pathlib
  2. class nick_in_use(Exception):
  3. def __init__(self, nick: str) -> None:
  4. super().__init__("Nick \"" + nick + "\" already in use.")
  5. class user_is_only_admin(Exception):
  6. def __init__(self) -> None:
  7. super().__init__("This user is only admin, can not being removed.")
  8. class invalid_nick_syntax(Exception):
  9. def __init__(self, nick: str, error: Exception) -> None:
  10. comment = "Nick \"" + nick + "\" has invalid syntax."
  11. comment = comment + "\nError: " + str(error)
  12. super().__init__(comment)
  13. class resources_directory_not_exists(Exception):
  14. def __init__(self, resources: pathlib.Path) -> None:
  15. comment = "Resources directory \"" + str(resources) + "\" does "
  16. comment = comment + "not exists."
  17. super().__init__(comment)
  18. class user_is_not_admin(Exception):
  19. def __init__(self):
  20. super().__init__("To do that action user must be admin.")
  21. class invalid_password_syntax(Exception):
  22. def __init__(self, password: str, error: Exception) -> None:
  23. comment = "Password \"" + password + "\" has invalid syntax."
  24. comment = comment + "\nError: " + str(error)
  25. super().__init__(comment)
  26. class invalid_apikey_syntax(Exception):
  27. def __init__(self, apikey: str, error: Exception) -> None:
  28. comment = "Api Key \"" + apikey + "\" has invalid syntax."
  29. comment = comment + "\nError: " + str(error)
  30. super().__init__(comment)
  31. class nick_not_exists(Exception):
  32. def __init__(self, nick: str) -> None:
  33. super().__init__("User with nick \"" + nick + "\" not exists.")
  34. class apikey_not_exists(Exception):
  35. def __init__(self, apikey: str) -> None:
  36. super().__init__("Api Key \"" + apikey + "\" does not exists.")
  37. class resources_not_exists(Exception):
  38. def __init__(self, target: pathlib.Path) -> None:
  39. comment = "Attachment file \"" + str(target) + "\" does not exists."
  40. super().__init__(comment)
  41. class model_must_being_saved(Exception):
  42. def __init__(self, target: object) -> None:
  43. comment = "To do that operation, model must being saved.\n"
  44. comment = comment + "Dump of the model: \n" + repr(target)
  45. super().__init__(comment)
  46. class not_exists(Exception):
  47. def __init__(self, target: object) -> None:
  48. comment = "Can not get identifier of object, which currently "
  49. comment = comment + "not exists.\nDump of the object:\n"
  50. comment = comment + repr(target)
  51. super().__init__(comment)
  52. class id_is_invalid(Exception):
  53. def __init__(self, id: int) -> None:
  54. super().__init__("Id \"" + str(id) + "\" is invalid.")
  55. class not_found(Exception):
  56. def __init__(self, name: str, **kwargs) -> None:
  57. comment = "Can not found " + name + " in database. "
  58. if len(kwargs) == 0:
  59. super().__init__(comment)
  60. return
  61. comment = comment + "Searching by: "
  62. for argument, value in kwargs.items():
  63. comment = comment + "\"" + argument + "\" = \""
  64. comment = comment + value + "\", "
  65. comment = comment[:-2]
  66. super().__init__(comment)