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.

errors.go 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // Copyright (c) 2012-2014 Jeremy Latt
  2. // Copyright (c) 2014-2015 Edmund Huber
  3. // Copyright (c) 2016-2017 Daniel Oaks <daniel@danieloaks.net>
  4. // released under the MIT license
  5. package irc
  6. import (
  7. "errors"
  8. "fmt"
  9. "time"
  10. "github.com/ergochat/ergo/irc/utils"
  11. )
  12. // Runtime Errors
  13. var (
  14. errAccountAlreadyRegistered = errors.New(`Account already exists`)
  15. errAccountAlreadyUnregistered = errors.New(`That account name was registered previously and can't be reused`)
  16. errAccountAlreadyVerified = errors.New(`Account is already verified`)
  17. errAccountCantDropPrimaryNick = errors.New("Can't unreserve primary nickname")
  18. errAccountCreation = errors.New("Account could not be created")
  19. errAccountDoesNotExist = errors.New("Account does not exist")
  20. errAccountInvalidCredentials = errors.New("Invalid account credentials")
  21. errAccountBadPassphrase = errors.New(`Passphrase contains forbidden characters or is otherwise invalid`)
  22. errAccountNickReservationFailed = errors.New("Could not (un)reserve nick")
  23. errAccountNotLoggedIn = errors.New("You're not logged into an account")
  24. errAccountAlreadyLoggedIn = errors.New("You're already logged into an account")
  25. errAccountTooManyNicks = errors.New("Account has too many reserved nicks")
  26. errAccountUnverified = errors.New(`Account is not yet verified`)
  27. errAccountSuspended = errors.New(`Account has been suspended`)
  28. errAccountVerificationFailed = errors.New("Account verification failed")
  29. errAccountVerificationInvalidCode = errors.New("Invalid account verification code")
  30. errAccountUpdateFailed = errors.New(`Error while updating your account information`)
  31. errAccountMustHoldNick = errors.New(`You must hold that nickname in order to register it`)
  32. errAuthzidAuthcidMismatch = errors.New(`authcid and authzid must be the same`)
  33. errCertfpAlreadyExists = errors.New(`An account already exists for your certificate fingerprint`)
  34. errChannelNotOwnedByAccount = errors.New("Channel not owned by the specified account")
  35. errChannelTransferNotOffered = errors.New(`You weren't offered ownership of that channel`)
  36. errChannelAlreadyRegistered = errors.New("Channel is already registered")
  37. errChannelNotRegistered = errors.New("Channel is not registered")
  38. errChannelNameInUse = errors.New(`Channel name in use`)
  39. errInvalidChannelName = errors.New(`Invalid channel name`)
  40. errMonitorLimitExceeded = errors.New("Monitor limit exceeded")
  41. errNickMissing = errors.New("nick missing")
  42. errNicknameInvalid = errors.New("invalid nickname")
  43. errNicknameInUse = errors.New("nickname in use")
  44. errInsecureReattach = errors.New("insecure reattach")
  45. errNicknameReserved = errors.New("nickname is reserved")
  46. errNickAccountMismatch = errors.New(`Your nickname must match your account name; try logging out and logging back in with SASL`)
  47. errNoExistingBan = errors.New("Ban does not exist")
  48. errNoSuchChannel = errors.New(`No such channel`)
  49. errChannelPurged = errors.New(`This channel was purged by the server operators and cannot be used`)
  50. errChannelPurgedAlready = errors.New(`This channel was already purged and cannot be purged again`)
  51. errConfusableIdentifier = errors.New("This identifier is confusable with one already in use")
  52. errInsufficientPrivs = errors.New("Insufficient privileges")
  53. errInvalidUsername = errors.New("Invalid username")
  54. errFeatureDisabled = errors.New(`That feature is disabled`)
  55. errBanned = errors.New("IP or nickmask banned")
  56. errInvalidParams = utils.ErrInvalidParams
  57. errNoVhost = errors.New(`You do not have an approved vhost`)
  58. errLimitExceeded = errors.New("Limit exceeded")
  59. errNoop = errors.New("Action was a no-op")
  60. errCASFailed = errors.New("Compare-and-swap update of database value failed")
  61. errEmptyCredentials = errors.New("No more credentials are approved")
  62. errCredsExternallyManaged = errors.New("Credentials are externally managed and cannot be changed here")
  63. errNoSCRAMCredentials = errors.New("SCRAM credentials are not initialized for this account; consult the user guide")
  64. errInvalidMultilineBatch = errors.New("Invalid multiline batch")
  65. errTimedOut = errors.New("Operation timed out")
  66. errInvalidUtf8 = errors.New("Message rejected for invalid utf8")
  67. errClientDestroyed = errors.New("Client was already destroyed")
  68. errTooManyChannels = errors.New("You have joined too many channels")
  69. errWrongChannelKey = errors.New("Cannot join password-protected channel without the password")
  70. errInviteOnly = errors.New("Cannot join invite-only channel without an invite")
  71. errRegisteredOnly = errors.New("Cannot join registered-only channel without an account")
  72. errValidEmailRequired = errors.New("A valid email address is required for account registration")
  73. errInvalidAccountRename = errors.New("Account renames can only change the casefolding of the account name")
  74. errNameReserved = errors.New(`Name reserved due to a prior registration`)
  75. errInvalidBearerTokenType = errors.New("invalid bearer token type")
  76. )
  77. // String Errors
  78. var (
  79. errCouldNotStabilize = errors.New("Could not stabilize string while casefolding")
  80. errStringIsEmpty = errors.New("String is empty")
  81. errInvalidCharacter = errors.New("Invalid character")
  82. )
  83. type CertKeyError struct {
  84. Err error
  85. }
  86. func (ck *CertKeyError) Error() string {
  87. return fmt.Sprintf("Invalid TLS cert/key pair: %v", ck.Err)
  88. }
  89. type ThrottleError struct {
  90. time.Duration
  91. }
  92. func (te *ThrottleError) Error() string {
  93. return fmt.Sprintf(`Please wait at least %v and try again`, te.Duration.Round(time.Millisecond))
  94. }