Browse Source

Move all errors into errors.go

tags/v0.11.0-beta
Daniel Oaks 6 years ago
parent
commit
2419f69879
17 changed files with 100 additions and 100 deletions
  1. 0
    6
      irc/accountreg.go
  2. 0
    4
      irc/accounts.go
  3. 1
    6
      irc/channel.go
  4. 7
    14
      irc/channelmanager.go
  5. 2
    5
      irc/client.go
  6. 2
    8
      irc/client_lookup_set.go
  7. 12
    13
      irc/config.go
  8. 0
    5
      irc/dline.go
  9. 54
    0
      irc/errors.go
  10. 1
    2
      irc/gateways.go
  11. 11
    11
      irc/handlers.go
  12. 1
    5
      irc/monitor.go
  13. 1
    1
      irc/nickname.go
  14. 1
    0
      irc/numerics.go
  15. 5
    8
      irc/server.go
  16. 0
    3
      irc/socket.go
  17. 2
    9
      irc/strings.go

+ 0
- 6
irc/accountreg.go View File

4
 package irc
4
 package irc
5
 
5
 
6
 import (
6
 import (
7
-	"errors"
8
 	"fmt"
7
 	"fmt"
9
 
8
 
10
 	"github.com/tidwall/buntdb"
9
 	"github.com/tidwall/buntdb"
11
 )
10
 )
12
 
11
 
13
-var (
14
-	errAccountCreation     = errors.New("Account could not be created")
15
-	errCertfpAlreadyExists = errors.New("An account already exists with your certificate")
16
-)
17
-
18
 // AccountRegistration manages the registration of accounts.
12
 // AccountRegistration manages the registration of accounts.
19
 type AccountRegistration struct {
13
 type AccountRegistration struct {
20
 	Enabled                    bool
14
 	Enabled                    bool

+ 0
- 4
irc/accounts.go View File

5
 
5
 
6
 import (
6
 import (
7
 	"encoding/json"
7
 	"encoding/json"
8
-	"errors"
9
 	"fmt"
8
 	"fmt"
10
 	"strconv"
9
 	"strconv"
11
 	"time"
10
 	"time"
37
 	NoAccount = ClientAccount{
36
 	NoAccount = ClientAccount{
38
 		Name: "*", // * is used until actual account name is set
37
 		Name: "*", // * is used until actual account name is set
39
 	}
38
 	}
40
-
41
-	// generic sasl fail error
42
-	errSaslFail = errors.New("SASL failed")
43
 )
39
 )
44
 
40
 
45
 // ClientAccount represents a user account.
41
 // ClientAccount represents a user account.

+ 1
- 6
irc/channel.go View File

6
 package irc
6
 package irc
7
 
7
 
8
 import (
8
 import (
9
-	"errors"
10
 	"fmt"
9
 	"fmt"
11
 	"strconv"
10
 	"strconv"
12
 	"time"
11
 	"time"
18
 	"github.com/oragono/oragono/irc/modes"
17
 	"github.com/oragono/oragono/irc/modes"
19
 )
18
 )
20
 
19
 
21
-var (
22
-	ChannelAlreadyRegistered = errors.New("Channel is already registered")
23
-)
24
-
25
 // Channel represents a channel that clients can join.
20
 // Channel represents a channel that clients can join.
26
 type Channel struct {
21
 type Channel struct {
27
 	flags             modes.ModeSet
22
 	flags             modes.ModeSet
132
 	defer channel.stateMutex.Unlock()
127
 	defer channel.stateMutex.Unlock()
133
 
128
 
134
 	if channel.registeredFounder != "" {
129
 	if channel.registeredFounder != "" {
135
-		return ChannelAlreadyRegistered
130
+		return errChannelAlreadyRegistered
136
 	}
131
 	}
137
 	channel.registeredFounder = founder
132
 	channel.registeredFounder = founder
138
 	channel.registeredTime = time.Now()
133
 	channel.registeredTime = time.Now()

+ 7
- 14
irc/channelmanager.go View File

4
 package irc
4
 package irc
5
 
5
 
6
 import (
6
 import (
7
-	"errors"
8
 	"sync"
7
 	"sync"
9
 )
8
 )
10
 
9
 
11
-var (
12
-	InvalidChannelName = errors.New("Invalid channel name")
13
-	NoSuchChannel      = errors.New("No such channel")
14
-	ChannelNameInUse   = errors.New("Channel name in use")
15
-)
16
-
17
 type channelManagerEntry struct {
10
 type channelManagerEntry struct {
18
 	channel *Channel
11
 	channel *Channel
19
 	// this is a refcount for joins, so we can avoid a race where we incorrectly
12
 	// this is a refcount for joins, so we can avoid a race where we incorrectly
56
 	server := client.server
49
 	server := client.server
57
 	casefoldedName, err := CasefoldChannel(name)
50
 	casefoldedName, err := CasefoldChannel(name)
58
 	if err != nil || len(casefoldedName) > server.Limits().ChannelLen {
51
 	if err != nil || len(casefoldedName) > server.Limits().ChannelLen {
59
-		return NoSuchChannel
52
+		return errNoSuchChannel
60
 	}
53
 	}
61
 
54
 
62
 	cm.Lock()
55
 	cm.Lock()
117
 func (cm *ChannelManager) Part(client *Client, name string, message string) error {
110
 func (cm *ChannelManager) Part(client *Client, name string, message string) error {
118
 	casefoldedName, err := CasefoldChannel(name)
111
 	casefoldedName, err := CasefoldChannel(name)
119
 	if err != nil {
112
 	if err != nil {
120
-		return NoSuchChannel
113
+		return errNoSuchChannel
121
 	}
114
 	}
122
 
115
 
123
 	cm.RLock()
116
 	cm.RLock()
125
 	cm.RUnlock()
118
 	cm.RUnlock()
126
 
119
 
127
 	if entry == nil {
120
 	if entry == nil {
128
-		return NoSuchChannel
121
+		return errNoSuchChannel
129
 	}
122
 	}
130
 	entry.channel.Part(client, message)
123
 	entry.channel.Part(client, message)
131
 	cm.maybeCleanup(entry, false)
124
 	cm.maybeCleanup(entry, false)
136
 func (cm *ChannelManager) Rename(name string, newname string) error {
129
 func (cm *ChannelManager) Rename(name string, newname string) error {
137
 	cfname, err := CasefoldChannel(name)
130
 	cfname, err := CasefoldChannel(name)
138
 	if err != nil {
131
 	if err != nil {
139
-		return NoSuchChannel
132
+		return errNoSuchChannel
140
 	}
133
 	}
141
 
134
 
142
 	cfnewname, err := CasefoldChannel(newname)
135
 	cfnewname, err := CasefoldChannel(newname)
143
 	if err != nil {
136
 	if err != nil {
144
-		return InvalidChannelName
137
+		return errInvalidChannelName
145
 	}
138
 	}
146
 
139
 
147
 	cm.Lock()
140
 	cm.Lock()
148
 	defer cm.Unlock()
141
 	defer cm.Unlock()
149
 
142
 
150
 	if cm.chans[cfnewname] != nil {
143
 	if cm.chans[cfnewname] != nil {
151
-		return ChannelNameInUse
144
+		return errChannelNameInUse
152
 	}
145
 	}
153
 	entry := cm.chans[cfname]
146
 	entry := cm.chans[cfname]
154
 	if entry == nil {
147
 	if entry == nil {
155
-		return NoSuchChannel
148
+		return errNoSuchChannel
156
 	}
149
 	}
157
 	delete(cm.chans, cfname)
150
 	delete(cm.chans, cfname)
158
 	cm.chans[cfnewname] = entry
151
 	cm.chans[cfnewname] = entry

+ 2
- 5
irc/client.go View File

6
 package irc
6
 package irc
7
 
7
 
8
 import (
8
 import (
9
-	"errors"
10
 	"fmt"
9
 	"fmt"
11
 	"log"
10
 	"log"
12
 	"net"
11
 	"net"
32
 )
31
 )
33
 
32
 
34
 var (
33
 var (
35
-	// ErrNickAlreadySet is a weird error that's sent when the server's consistency has been compromised.
36
-	ErrNickAlreadySet = errors.New("Nickname is already set")
37
-	LoopbackIP        = net.ParseIP("127.0.0.1")
34
+	LoopbackIP = net.ParseIP("127.0.0.1")
38
 )
35
 )
39
 
36
 
40
 // Client is an IRC client.
37
 // Client is an IRC client.
397
 		var params []string
394
 		var params []string
398
 		if 0 < len(oldModes) {
395
 		if 0 < len(oldModes) {
399
 			params = []string{channel.name, "+" + oldModes}
396
 			params = []string{channel.name, "+" + oldModes}
400
-			for _ = range oldModes {
397
+			for range oldModes {
401
 				params = append(params, client.nick)
398
 				params = append(params, client.nick)
402
 			}
399
 			}
403
 		}
400
 		}

+ 2
- 8
irc/client_lookup_set.go View File

5
 package irc
5
 package irc
6
 
6
 
7
 import (
7
 import (
8
-	"errors"
9
 	"fmt"
8
 	"fmt"
10
 	"log"
9
 	"log"
11
 	"regexp"
10
 	"regexp"
17
 	"sync"
16
 	"sync"
18
 )
17
 )
19
 
18
 
20
-var (
21
-	ErrNickMissing   = errors.New("nick missing")
22
-	ErrNicknameInUse = errors.New("nickname in use")
23
-)
24
-
25
 // ExpandUserHost takes a userhost, and returns an expanded version.
19
 // ExpandUserHost takes a userhost, and returns an expanded version.
26
 func ExpandUserHost(userhost string) (expanded string) {
20
 func ExpandUserHost(userhost string) (expanded string) {
27
 	expanded = userhost
21
 	expanded = userhost
91
 	defer clients.Unlock()
85
 	defer clients.Unlock()
92
 
86
 
93
 	if !client.HasNick() {
87
 	if !client.HasNick() {
94
-		return ErrNickMissing
88
+		return errNickMissing
95
 	}
89
 	}
96
 	clients.removeInternal(client)
90
 	clients.removeInternal(client)
97
 	return nil
91
 	return nil
111
 	currentNewEntry := clients.byNick[newcfnick]
105
 	currentNewEntry := clients.byNick[newcfnick]
112
 	// the client may just be changing case
106
 	// the client may just be changing case
113
 	if currentNewEntry != nil && currentNewEntry != client {
107
 	if currentNewEntry != nil && currentNewEntry != client {
114
-		return ErrNicknameInUse
108
+		return errNicknameInUse
115
 	}
109
 	}
116
 	clients.byNick[newcfnick] = client
110
 	clients.byNick[newcfnick] = client
117
 	client.updateNickMask(newNick)
111
 	client.updateNickMask(newNick)

+ 12
- 13
irc/config.go View File

8
 import (
8
 import (
9
 	"crypto/tls"
9
 	"crypto/tls"
10
 	"encoding/json"
10
 	"encoding/json"
11
-	"errors"
12
 	"fmt"
11
 	"fmt"
13
 	"io/ioutil"
12
 	"io/ioutil"
14
 	"log"
13
 	"log"
41
 func (conf *TLSListenConfig) Config() (*tls.Config, error) {
40
 func (conf *TLSListenConfig) Config() (*tls.Config, error) {
42
 	cert, err := tls.LoadX509KeyPair(conf.Cert, conf.Key)
41
 	cert, err := tls.LoadX509KeyPair(conf.Cert, conf.Key)
43
 	if err != nil {
42
 	if err != nil {
44
-		return nil, errors.New("tls cert+key: invalid pair")
43
+		return nil, ErrInvalidCertKeyPair
45
 	}
44
 	}
46
 
45
 
47
 	return &tls.Config{
46
 	return &tls.Config{
232
 	lenOfLastOcs := -1
231
 	lenOfLastOcs := -1
233
 	for {
232
 	for {
234
 		if lenOfLastOcs == len(ocs) {
233
 		if lenOfLastOcs == len(ocs) {
235
-			return nil, errors.New("OperClasses contains a looping dependency, or a class extends from a class that doesn't exist")
234
+			return nil, ErrOperClassDependencies
236
 		}
235
 		}
237
 		lenOfLastOcs = len(ocs)
236
 		lenOfLastOcs = len(ocs)
238
 
237
 
369
 	}
368
 	}
370
 
369
 
371
 	if config.Network.Name == "" {
370
 	if config.Network.Name == "" {
372
-		return nil, errors.New("Network name missing")
371
+		return nil, ErrNetworkNameMissing
373
 	}
372
 	}
374
 	if config.Server.Name == "" {
373
 	if config.Server.Name == "" {
375
-		return nil, errors.New("Server name missing")
374
+		return nil, ErrServerNameMissing
376
 	}
375
 	}
377
 	if !utils.IsHostname(config.Server.Name) {
376
 	if !utils.IsHostname(config.Server.Name) {
378
-		return nil, errors.New("Server name must match the format of a hostname")
377
+		return nil, ErrServerNameNotHostname
379
 	}
378
 	}
380
 	if config.Datastore.Path == "" {
379
 	if config.Datastore.Path == "" {
381
-		return nil, errors.New("Datastore path missing")
380
+		return nil, ErrDatastorePathMissing
382
 	}
381
 	}
383
 	if len(config.Server.Listen) == 0 {
382
 	if len(config.Server.Listen) == 0 {
384
-		return nil, errors.New("Server listening addresses missing")
383
+		return nil, ErrNoListenersDefined
385
 	}
384
 	}
386
 	if config.Limits.NickLen < 1 || config.Limits.ChannelLen < 2 || config.Limits.AwayLen < 1 || config.Limits.KickLen < 1 || config.Limits.TopicLen < 1 {
385
 	if config.Limits.NickLen < 1 || config.Limits.ChannelLen < 2 || config.Limits.AwayLen < 1 || config.Limits.KickLen < 1 || config.Limits.TopicLen < 1 {
387
-		return nil, errors.New("Limits aren't setup properly, check them and make them sane")
386
+		return nil, ErrLimitsAreInsane
388
 	}
387
 	}
389
 	if config.Server.STS.Enabled {
388
 	if config.Server.STS.Enabled {
390
 		config.Server.STS.Duration, err = custime.ParseDuration(config.Server.STS.DurationString)
389
 		config.Server.STS.Duration, err = custime.ParseDuration(config.Server.STS.DurationString)
422
 	config.Server.WebIRC = newWebIRC
421
 	config.Server.WebIRC = newWebIRC
423
 	// process limits
422
 	// process limits
424
 	if config.Limits.LineLen.Tags < 512 || config.Limits.LineLen.Rest < 512 {
423
 	if config.Limits.LineLen.Tags < 512 || config.Limits.LineLen.Rest < 512 {
425
-		return nil, errors.New("Line lengths must be 512 or greater (check the linelen section under server->limits)")
424
+		return nil, ErrLineLengthsTooSmall
426
 	}
425
 	}
427
 	var newLogConfigs []logger.LoggingConfig
426
 	var newLogConfigs []logger.LoggingConfig
428
 	for _, logConfig := range config.Logging {
427
 	for _, logConfig := range config.Logging {
434
 			}
433
 			}
435
 		}
434
 		}
436
 		if methods["file"] && logConfig.Filename == "" {
435
 		if methods["file"] && logConfig.Filename == "" {
437
-			return nil, errors.New("Logging configuration specifies 'file' method but 'filename' is empty")
436
+			return nil, ErrLoggerFilenameMissing
438
 		}
437
 		}
439
 		logConfig.MethodFile = methods["file"]
438
 		logConfig.MethodFile = methods["file"]
440
 		logConfig.MethodStdout = methods["stdout"]
439
 		logConfig.MethodStdout = methods["stdout"]
453
 				continue
452
 				continue
454
 			}
453
 			}
455
 			if typeStr == "-" {
454
 			if typeStr == "-" {
456
-				return nil, errors.New("Encountered logging type '-' with no type to exclude")
455
+				return nil, ErrLoggerExcludeEmpty
457
 			}
456
 			}
458
 			if typeStr[0] == '-' {
457
 			if typeStr[0] == '-' {
459
 				typeStr = typeStr[1:]
458
 				typeStr = typeStr[1:]
463
 			}
462
 			}
464
 		}
463
 		}
465
 		if len(logConfig.Types) < 1 {
464
 		if len(logConfig.Types) < 1 {
466
-			return nil, errors.New("Logger has no types to log")
465
+			return nil, ErrLoggerHasNoTypes
467
 		}
466
 		}
468
 
467
 
469
 		newLogConfigs = append(newLogConfigs, logConfig)
468
 		newLogConfigs = append(newLogConfigs, logConfig)

+ 0
- 5
irc/dline.go View File

4
 package irc
4
 package irc
5
 
5
 
6
 import (
6
 import (
7
-	"errors"
8
 	"fmt"
7
 	"fmt"
9
 	"net"
8
 	"net"
10
 	"sync"
9
 	"sync"
19
 	keyDlineEntry = "bans.dline %s"
18
 	keyDlineEntry = "bans.dline %s"
20
 )
19
 )
21
 
20
 
22
-var (
23
-	errNoExistingBan = errors.New("Ban does not exist")
24
-)
25
-
26
 // IPRestrictTime contains the expiration info about the given IP.
21
 // IPRestrictTime contains the expiration info about the given IP.
27
 type IPRestrictTime struct {
22
 type IPRestrictTime struct {
28
 	// Duration is how long this block lasts for.
23
 	// Duration is how long this block lasts for.

+ 54
- 0
irc/errors.go View File

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
+
6
+package irc
7
+
8
+import "errors"
9
+
10
+// Runtime Errors
11
+var (
12
+	errAccountCreation          = errors.New("Account could not be created")
13
+	errCertfpAlreadyExists      = errors.New("An account already exists with your certificate")
14
+	errChannelAlreadyRegistered = errors.New("Channel is already registered")
15
+	errChannelNameInUse         = errors.New("Channel name in use")
16
+	errInvalidChannelName       = errors.New("Invalid channel name")
17
+	errMonitorLimitExceeded     = errors.New("Monitor limit exceeded")
18
+	errNickMissing              = errors.New("nick missing")
19
+	errNicknameInUse            = errors.New("nickname in use")
20
+	errNoExistingBan            = errors.New("Ban does not exist")
21
+	errNoSuchChannel            = errors.New("No such channel")
22
+	errRenamePrivsNeeded        = errors.New("Only chanops can rename channels")
23
+	errSaslFail                 = errors.New("SASL failed")
24
+)
25
+
26
+// Socket Errors
27
+var (
28
+	errNoPeerCerts = errors.New("Client did not provide a certificate")
29
+	errNotTLS      = errors.New("Not a TLS connection")
30
+)
31
+
32
+// String Errors
33
+var (
34
+	errCouldNotStabilize = errors.New("Could not stabilize string while casefolding")
35
+	errStringIsEmpty     = errors.New("String is empty")
36
+	errInvalidCharacter  = errors.New("Invalid character")
37
+)
38
+
39
+// Config Errors
40
+var (
41
+	ErrDatastorePathMissing    = errors.New("Datastore path missing")
42
+	ErrInvalidCertKeyPair      = errors.New("tls cert+key: invalid pair")
43
+	ErrLimitsAreInsane         = errors.New("Limits aren't setup properly, check them and make them sane")
44
+	ErrLineLengthsTooSmall     = errors.New("Line lengths must be 512 or greater (check the linelen section under server->limits)")
45
+	ErrLoggerExcludeEmpty      = errors.New("Encountered logging type '-' with no type to exclude")
46
+	ErrLoggerFilenameMissing   = errors.New("Logging configuration specifies 'file' method but 'filename' is empty")
47
+	ErrLoggerHasNoTypes        = errors.New("Logger has no types to log")
48
+	ErrNetworkNameMissing      = errors.New("Network name missing")
49
+	ErrNoFingerprintOrPassword = errors.New("Fingerprint or password needs to be specified")
50
+	ErrNoListenersDefined      = errors.New("Server listening addresses missing")
51
+	ErrOperClassDependencies   = errors.New("OperClasses contains a looping dependency, or a class extends from a class that doesn't exist")
52
+	ErrServerNameMissing       = errors.New("Server name missing")
53
+	ErrServerNameNotHostname   = errors.New("Server name must match the format of a hostname")
54
+)

+ 1
- 2
irc/gateways.go View File

6
 package irc
6
 package irc
7
 
7
 
8
 import (
8
 import (
9
-	"errors"
10
 	"fmt"
9
 	"fmt"
11
 	"net"
10
 	"net"
12
 
11
 
25
 // Populate fills out our password or fingerprint.
24
 // Populate fills out our password or fingerprint.
26
 func (wc *webircConfig) Populate() (err error) {
25
 func (wc *webircConfig) Populate() (err error) {
27
 	if wc.Fingerprint == "" && wc.PasswordString == "" {
26
 	if wc.Fingerprint == "" && wc.PasswordString == "" {
28
-		return errors.New("Fingerprint or password needs to be specified")
27
+		return ErrNoFingerprintOrPassword
29
 	}
28
 	}
30
 
29
 
31
 	if wc.PasswordString != "" {
30
 	if wc.PasswordString != "" {

+ 11
- 11
irc/handlers.go View File

976
 			key = keys[i]
976
 			key = keys[i]
977
 		}
977
 		}
978
 		err := server.channels.Join(client, name, key)
978
 		err := server.channels.Join(client, name, key)
979
-		if err == NoSuchChannel {
979
+		if err == errNoSuchChannel {
980
 			client.Send(nil, server.name, ERR_NOSUCHCHANNEL, client.Nick(), name, client.t("No such channel"))
980
 			client.Send(nil, server.name, ERR_NOSUCHCHANNEL, client.Nick(), name, client.t("No such channel"))
981
 		}
981
 		}
982
 	}
982
 	}
1571
 		}
1571
 		}
1572
 
1572
 
1573
 		err = server.monitorManager.Add(client, casefoldedTarget, limit)
1573
 		err = server.monitorManager.Add(client, casefoldedTarget, limit)
1574
-		if err == ErrMonitorLimitExceeded {
1574
+		if err == errMonitorLimitExceeded {
1575
 			client.Send(nil, server.name, ERR_MONLISTFULL, client.Nick(), strconv.Itoa(server.limits.MonitorEntries), strings.Join(targets, ","))
1575
 			client.Send(nil, server.name, ERR_MONLISTFULL, client.Nick(), strconv.Itoa(server.limits.MonitorEntries), strings.Join(targets, ","))
1576
 			break
1576
 			break
1577
 		} else if err != nil {
1577
 		} else if err != nil {
1855
 
1855
 
1856
 	for _, chname := range channels {
1856
 	for _, chname := range channels {
1857
 		err := server.channels.Part(client, chname, reason)
1857
 		err := server.channels.Part(client, chname, reason)
1858
-		if err == NoSuchChannel {
1858
+		if err == errNoSuchChannel {
1859
 			client.Send(nil, server.name, ERR_NOSUCHCHANNEL, client.nick, chname, client.t("No such channel"))
1859
 			client.Send(nil, server.name, ERR_NOSUCHCHANNEL, client.nick, chname, client.t("No such channel"))
1860
 		}
1860
 		}
1861
 	}
1861
 	}
2023
 		// TODO: send correct error codes, e.g., ERR_CANNOTRENAME, ERR_CHANNAMEINUSE
2023
 		// TODO: send correct error codes, e.g., ERR_CANNOTRENAME, ERR_CHANNAMEINUSE
2024
 		var code string
2024
 		var code string
2025
 		switch err {
2025
 		switch err {
2026
-		case NoSuchChannel:
2026
+		case errNoSuchChannel:
2027
 			code = ERR_NOSUCHCHANNEL
2027
 			code = ERR_NOSUCHCHANNEL
2028
-		case RenamePrivsNeeded:
2028
+		case errRenamePrivsNeeded:
2029
 			code = ERR_CHANOPRIVSNEEDED
2029
 			code = ERR_CHANOPRIVSNEEDED
2030
-		case InvalidChannelName:
2030
+		case errInvalidChannelName:
2031
 			code = ERR_UNKNOWNERROR
2031
 			code = ERR_UNKNOWNERROR
2032
-		case ChannelNameInUse:
2032
+		case errChannelNameInUse:
2033
 			code = ERR_UNKNOWNERROR
2033
 			code = ERR_UNKNOWNERROR
2034
 		default:
2034
 		default:
2035
 			code = ERR_UNKNOWNERROR
2035
 			code = ERR_UNKNOWNERROR
2040
 	oldName := strings.TrimSpace(msg.Params[0])
2040
 	oldName := strings.TrimSpace(msg.Params[0])
2041
 	newName := strings.TrimSpace(msg.Params[1])
2041
 	newName := strings.TrimSpace(msg.Params[1])
2042
 	if oldName == "" || newName == "" {
2042
 	if oldName == "" || newName == "" {
2043
-		errorResponse(InvalidChannelName, "<empty>")
2043
+		errorResponse(errInvalidChannelName, "<empty>")
2044
 		return
2044
 		return
2045
 	}
2045
 	}
2046
 	casefoldedOldName, err := CasefoldChannel(oldName)
2046
 	casefoldedOldName, err := CasefoldChannel(oldName)
2047
 	if err != nil {
2047
 	if err != nil {
2048
-		errorResponse(InvalidChannelName, oldName)
2048
+		errorResponse(errInvalidChannelName, oldName)
2049
 		return
2049
 		return
2050
 	}
2050
 	}
2051
 
2051
 
2056
 
2056
 
2057
 	channel := server.channels.Get(oldName)
2057
 	channel := server.channels.Get(oldName)
2058
 	if channel == nil {
2058
 	if channel == nil {
2059
-		errorResponse(NoSuchChannel, oldName)
2059
+		errorResponse(errNoSuchChannel, oldName)
2060
 		return
2060
 		return
2061
 	}
2061
 	}
2062
 	//TODO(dan): allow IRCops to do this?
2062
 	//TODO(dan): allow IRCops to do this?
2063
 	if !channel.ClientIsAtLeast(client, modes.Operator) {
2063
 	if !channel.ClientIsAtLeast(client, modes.Operator) {
2064
-		errorResponse(RenamePrivsNeeded, oldName)
2064
+		errorResponse(errRenamePrivsNeeded, oldName)
2065
 		return
2065
 		return
2066
 	}
2066
 	}
2067
 
2067
 

+ 1
- 5
irc/monitor.go View File

4
 package irc
4
 package irc
5
 
5
 
6
 import (
6
 import (
7
-	"errors"
8
 	"sync"
7
 	"sync"
9
 
8
 
10
 	"github.com/goshuirc/irc-go/ircmsg"
9
 	"github.com/goshuirc/irc-go/ircmsg"
29
 	return &mm
28
 	return &mm
30
 }
29
 }
31
 
30
 
32
-// ErrMonitorLimitExceeded is used when the monitor list exceeds our limit.
33
-var ErrMonitorLimitExceeded = errors.New("Monitor limit exceeded")
34
-
35
 // AlertAbout alerts everyone monitoring `client`'s nick that `client` is now {on,off}line.
31
 // AlertAbout alerts everyone monitoring `client`'s nick that `client` is now {on,off}line.
36
 func (manager *MonitorManager) AlertAbout(client *Client, online bool) {
32
 func (manager *MonitorManager) AlertAbout(client *Client, online bool) {
37
 	cfnick := client.NickCasefolded()
33
 	cfnick := client.NickCasefolded()
67
 	}
63
 	}
68
 
64
 
69
 	if len(manager.watching[client]) >= limit {
65
 	if len(manager.watching[client]) >= limit {
70
-		return ErrMonitorLimitExceeded
66
+		return errMonitorLimitExceeded
71
 	}
67
 	}
72
 
68
 
73
 	manager.watching[client][nick] = true
69
 	manager.watching[client][nick] = true

+ 1
- 1
irc/nickname.go View File

42
 	origNick := target.Nick()
42
 	origNick := target.Nick()
43
 	origNickMask := target.NickMaskString()
43
 	origNickMask := target.NickMaskString()
44
 	err = client.server.clients.SetNick(target, nickname)
44
 	err = client.server.clients.SetNick(target, nickname)
45
-	if err == ErrNicknameInUse {
45
+	if err == errNicknameInUse {
46
 		client.Send(nil, server.name, ERR_NICKNAMEINUSE, client.nick, nickname, client.t("Nickname is already in use"))
46
 		client.Send(nil, server.name, ERR_NICKNAMEINUSE, client.nick, nickname, client.t("Nickname is already in use"))
47
 		return false
47
 		return false
48
 	} else if err != nil {
48
 	} else if err != nil {

+ 1
- 0
irc/numerics.go View File

195
 	ERR_NOLANGUAGE                  = "982"
195
 	ERR_NOLANGUAGE                  = "982"
196
 
196
 
197
 	// draft numerics
197
 	// draft numerics
198
+
198
 	ERR_CANNOT_RESUME = "999"
199
 	ERR_CANNOT_RESUME = "999"
199
 )
200
 )

+ 5
- 8
irc/server.go View File

9
 	"bufio"
9
 	"bufio"
10
 	"crypto/tls"
10
 	"crypto/tls"
11
 	"encoding/base64"
11
 	"encoding/base64"
12
-	"errors"
13
 	"fmt"
12
 	"fmt"
14
 	"log"
13
 	"log"
15
 	"math/rand"
14
 	"math/rand"
43
 	// common error responses
42
 	// common error responses
44
 	couldNotParseIPMsg, _ = (&[]ircmsg.IrcMessage{ircmsg.MakeMessage(nil, "", "ERROR", "Unable to parse your IP address")}[0]).Line()
43
 	couldNotParseIPMsg, _ = (&[]ircmsg.IrcMessage{ircmsg.MakeMessage(nil, "", "ERROR", "Unable to parse your IP address")}[0]).Line()
45
 
44
 
46
-	RenamePrivsNeeded = errors.New("Only chanops can rename channels")
47
-
48
 	// supportedUserModesString acts as a cache for when we introduce users
45
 	// supportedUserModesString acts as a cache for when we introduce users
49
 	supportedUserModesString = modes.SupportedUserModes.String()
46
 	supportedUserModesString = modes.SupportedUserModes.String()
50
 	// supportedChannelModesString acts as a cache for when we introduce users
47
 	// supportedChannelModesString acts as a cache for when we introduce users
349
 	// make listener
346
 	// make listener
350
 	var listener net.Listener
347
 	var listener net.Listener
351
 	var err error
348
 	var err error
352
-	optional_unix_prefix := "unix:"
353
-	optional_prefix_len := len(optional_unix_prefix)
354
-	if len(addr) >= optional_prefix_len && strings.ToLower(addr[0:optional_prefix_len]) == optional_unix_prefix {
355
-		addr = addr[optional_prefix_len:]
349
+	optionalUnixPrefix := "unix:"
350
+	optionalPrefixLen := len(optionalUnixPrefix)
351
+	if len(addr) >= optionalPrefixLen && strings.ToLower(addr[0:optionalPrefixLen]) == optionalUnixPrefix {
352
+		addr = addr[optionalPrefixLen:]
356
 		if len(addr) == 0 || addr[0] != '/' {
353
 		if len(addr) == 0 || addr[0] != '/' {
357
 			log.Fatal("Bad unix socket address", addr)
354
 			log.Fatal("Bad unix socket address", addr)
358
 		}
355
 		}
492
 			oldModes := myModes.String()
489
 			oldModes := myModes.String()
493
 			if 0 < len(oldModes) {
490
 			if 0 < len(oldModes) {
494
 				params := []string{channel.name, "+" + oldModes}
491
 				params := []string{channel.name, "+" + oldModes}
495
-				for _ = range oldModes {
492
+				for range oldModes {
496
 					params = append(params, c.nick)
493
 					params = append(params, c.nick)
497
 				}
494
 				}
498
 
495
 

+ 0
- 3
irc/socket.go View File

9
 	"crypto/sha256"
9
 	"crypto/sha256"
10
 	"crypto/tls"
10
 	"crypto/tls"
11
 	"encoding/hex"
11
 	"encoding/hex"
12
-	"errors"
13
 	"io"
12
 	"io"
14
 	"net"
13
 	"net"
15
 	"strings"
14
 	"strings"
18
 )
17
 )
19
 
18
 
20
 var (
19
 var (
21
-	errNotTLS           = errors.New("Not a TLS connection")
22
-	errNoPeerCerts      = errors.New("Client did not provide a certificate")
23
 	handshakeTimeout, _ = time.ParseDuration("5s")
20
 	handshakeTimeout, _ = time.ParseDuration("5s")
24
 )
21
 )
25
 
22
 

+ 2
- 9
irc/strings.go View File

6
 package irc
6
 package irc
7
 
7
 
8
 import (
8
 import (
9
-	"errors"
10
 	"strings"
9
 	"strings"
11
 
10
 
12
 	"golang.org/x/text/secure/precis"
11
 	"golang.org/x/text/secure/precis"
16
 	casemappingName = "rfc8265"
15
 	casemappingName = "rfc8265"
17
 )
16
 )
18
 
17
 
19
-var (
20
-	errCouldNotStabilize = errors.New("Could not stabilize string while casefolding")
21
-	errInvalidCharacter  = errors.New("Invalid character")
22
-	errEmpty             = errors.New("String is empty")
23
-)
24
-
25
 // Casefold returns a casefolded string, without doing any name or channel character checks.
18
 // Casefold returns a casefolded string, without doing any name or channel character checks.
26
 func Casefold(str string) (string, error) {
19
 func Casefold(str string) (string, error) {
27
 	var err error
20
 	var err error
51
 	if err != nil {
44
 	if err != nil {
52
 		return "", err
45
 		return "", err
53
 	} else if len(lowered) == 0 {
46
 	} else if len(lowered) == 0 {
54
-		return "", errEmpty
47
+		return "", errStringIsEmpty
55
 	}
48
 	}
56
 
49
 
57
 	if lowered[0] != '#' {
50
 	if lowered[0] != '#' {
76
 	if err != nil {
69
 	if err != nil {
77
 		return "", err
70
 		return "", err
78
 	} else if len(lowered) == 0 {
71
 	} else if len(lowered) == 0 {
79
-		return "", errEmpty
72
+		return "", errStringIsEmpty
80
 	}
73
 	}
81
 
74
 
82
 	// space can't be used
75
 	// space can't be used

Loading…
Cancel
Save