exceptions.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #!/usr/bin/env python3
  2. #
  3. # This program is made by the World Sus Foundation by Andrew.
  4. #
  5. # Various utility functions for the Internet Delay Chat server written
  6. # in Python Trio. This library is not intended to be used outside of
  7. # that program.
  8. #
  9. # Written by: Andrew <https://www.andrewyu.org>
  10. # luk3yx <https://luk3yx.github.io>
  11. #
  12. # This is free and unencumbered software released into the public
  13. # domain.
  14. #
  15. # Anyone is free to copy, modify, publish, use, compile, sell, or
  16. # distribute this software, either in source code form or as a compiled
  17. # binary, for any purpose, commercial or non-commercial, and by any
  18. # means.
  19. #
  20. # In jurisdictions that recognize copyright laws, the author or authors
  21. # of this software dedicate any and all copyright interest in the
  22. # software to the public domain. We make this dedication for the benefit
  23. # of the public at large and to the detriment of our heirs and
  24. # successors. We intend this dedication to be an overt act of
  25. # relinquishment in perpetuity of all present and future rights to this
  26. # software under copyright law.
  27. #
  28. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  29. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  30. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  31. # IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  32. # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  33. # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  34. # OTHER DEALINGS IN THE SOFTWARE.
  35. class Severity:
  36. UNKNOWN = b"UNKNOWN"
  37. YAY = b"YAY"
  38. NORM = b"NORM"
  39. FAIL = b"FAIL"
  40. WARN = b"WARN"
  41. ERROR = b"ERROR"
  42. SECURITY = b"SECURITY"
  43. FATAL = b"FATAL"
  44. THE_PROGRAMMER_IS_DUMB = b"THE_PROGRAMMER_IS_DUMB"
  45. class IDCException(Exception):
  46. severity = Severity.UNKNOWN
  47. error_type = b"UNKNOWN"
  48. class IdiotError(IDCException):
  49. severity = Severity.THE_PROGRAMMER_IS_DUMB
  50. error_type = b"YOU_DUMB_DEVELOPER"
  51. class IDCUserCausedException(IDCException):
  52. """
  53. Should be subclassed by all of the 'user did something wrong' errors
  54. """
  55. severity = Severity.ERROR
  56. error_type = b"USER_ERROR"
  57. pass
  58. class UnknownCommand(IDCUserCausedException):
  59. error_type = b"UNKNOWN_COMMAND"
  60. class MissingArgumentError(IDCUserCausedException):
  61. error_type = b"MISSING_ARGUMENT"
  62. class NotLoggedIn(IDCUserCausedException):
  63. error_type = b"NOT_LOGGED_IN"
  64. class AlreadyLoggedIn(IDCUserCausedException):
  65. error_type = b"REDUNDENT_LOGIN"
  66. class LoginFailed(IDCUserCausedException):
  67. severity = Severity.FAIL
  68. error_type = b"LOGIN_FAILED"
  69. class NonAlphaKeyError(IDCUserCausedException):
  70. """
  71. Putting non-letters into keywords
  72. """
  73. error_type = b"INVALID_KEYWORD"
  74. class EscapeSequenceError(IDCUserCausedException):
  75. """
  76. I don't know this escape sequence
  77. """
  78. error_type = b"DONT_KNOW"
  79. class MultiCommandError(IDCUserCausedException):
  80. """
  81. Multiple commands in one line
  82. """
  83. error_type = b"MULTIPLE_CMDS"
  84. class MessageUndeliverableError(IDCUserCausedException):
  85. """
  86. User to deliver message to is offline and doesn't have the
  87. offline-messages option.
  88. """
  89. error_type = b"MSG_UNDELIVERABLE"
  90. class UserNotFoundError(IDCUserCausedException):
  91. """
  92. Raise this for clients trying to message, modify, or otherwise
  93. interact with a nonexistant user.
  94. """
  95. error_type = b"USER_NOT_FOUND"
  96. class StrangeError(IDCException):
  97. """
  98. Random errors that shouldn't exist and were probably caused by
  99. either the hardware blowing up or huge bugs.
  100. """
  101. error_type = b"DONT_KNOW"
  102. class KeyCollisionError(IDCUserCausedException):
  103. """
  104. Raise when there are redundent keys in a line.
  105. """
  106. error_type = b"REDUNDENT_KEYS"
  107. class NonexistantTargetError(IDCUserCausedException):
  108. """
  109. target doesnt exist
  110. """
  111. error_type = b"NONEXISTANT_TARGET"
  112. class NoExternalMessagesError(IDCUserCausedException):
  113. """
  114. sender not in chan
  115. """
  116. error_type = b"NO_EXTERNAL_MESSAGES"
  117. class TargetOfflineError(IDCUserCausedException):
  118. """
  119. Target offline
  120. """
  121. error_type = b"TARGET_OFFLINE"