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