Преглед на файлове

Move config errors to call sites

Since allocating them is rare.
tags/v2.3.0-rc1
Shivaram Lingamneni преди 3 години
родител
ревизия
9000383f88
променени са 3 файла, в които са добавени 10 реда и са изтрити 25 реда
  1. 9
    9
      irc/config.go
  2. 0
    15
      irc/errors.go
  3. 1
    1
      irc/gateways.go

+ 9
- 9
irc/config.go Целия файл

@@ -640,7 +640,7 @@ func (conf *Config) OperatorClasses() (map[string]*OperClass, error) {
640 640
 	lenOfLastOcs := -1
641 641
 	for {
642 642
 		if lenOfLastOcs == len(ocs) {
643
-			return nil, ErrOperClassDependencies
643
+			return nil, errors.New("OperClasses contains a looping dependency, or a class extends from a class that doesn't exist")
644 644
 		}
645 645
 		lenOfLastOcs = len(ocs)
646 646
 
@@ -869,24 +869,24 @@ func LoadConfig(filename string) (config *Config, err error) {
869 869
 	config.Filename = filename
870 870
 
871 871
 	if config.Network.Name == "" {
872
-		return nil, ErrNetworkNameMissing
872
+		return nil, errors.New("Network name missing")
873 873
 	}
874 874
 	if config.Server.Name == "" {
875
-		return nil, ErrServerNameMissing
875
+		return nil, errors.New("Server name missing")
876 876
 	}
877 877
 	if !utils.IsServerName(config.Server.Name) {
878
-		return nil, ErrServerNameNotHostname
878
+		return nil, errors.New("Server name must match the format of a hostname")
879 879
 	}
880 880
 	config.Server.nameCasefolded = strings.ToLower(config.Server.Name)
881 881
 	if config.Datastore.Path == "" {
882
-		return nil, ErrDatastorePathMissing
882
+		return nil, errors.New("Datastore path missing")
883 883
 	}
884 884
 	//dan: automagically fix identlen until a few releases in the future (from now, 0.12.0), being a newly-introduced limit
885 885
 	if config.Limits.IdentLen < 1 {
886 886
 		config.Limits.IdentLen = 20
887 887
 	}
888 888
 	if config.Limits.NickLen < 1 || config.Limits.ChannelLen < 2 || config.Limits.AwayLen < 1 || config.Limits.KickLen < 1 || config.Limits.TopicLen < 1 {
889
-		return nil, ErrLimitsAreInsane
889
+		return nil, errors.New("One or more limits values are too low")
890 890
 	}
891 891
 	if config.Limits.RegistrationMessages == 0 {
892 892
 		config.Limits.RegistrationMessages = 1024
@@ -999,7 +999,7 @@ func LoadConfig(filename string) (config *Config, err error) {
999 999
 			}
1000 1000
 		}
1001 1001
 		if methods["file"] && logConfig.Filename == "" {
1002
-			return nil, ErrLoggerFilenameMissing
1002
+			return nil, errors.New("Logging configuration specifies 'file' method but 'filename' is empty")
1003 1003
 		}
1004 1004
 		logConfig.MethodFile = methods["file"]
1005 1005
 		logConfig.MethodStdout = methods["stdout"]
@@ -1018,7 +1018,7 @@ func LoadConfig(filename string) (config *Config, err error) {
1018 1018
 				continue
1019 1019
 			}
1020 1020
 			if typeStr == "-" {
1021
-				return nil, ErrLoggerExcludeEmpty
1021
+				return nil, errors.New("Encountered logging type '-' with no type to exclude")
1022 1022
 			}
1023 1023
 			if typeStr[0] == '-' {
1024 1024
 				typeStr = typeStr[1:]
@@ -1028,7 +1028,7 @@ func LoadConfig(filename string) (config *Config, err error) {
1028 1028
 			}
1029 1029
 		}
1030 1030
 		if len(logConfig.Types) < 1 {
1031
-			return nil, ErrLoggerHasNoTypes
1031
+			return nil, errors.New("Logger has no types to log")
1032 1032
 		}
1033 1033
 
1034 1034
 		newLogConfigs = append(newLogConfigs, logConfig)

+ 0
- 15
irc/errors.go Целия файл

@@ -102,18 +102,3 @@ type ThrottleError struct {
102 102
 func (te *ThrottleError) Error() string {
103 103
 	return fmt.Sprintf(`Please wait at least %v and try again`, te.Duration)
104 104
 }
105
-
106
-// Config Errors
107
-var (
108
-	ErrDatastorePathMissing    = errors.New("Datastore path missing")
109
-	ErrLimitsAreInsane         = errors.New("Limits aren't setup properly, check them and make them sane")
110
-	ErrLoggerExcludeEmpty      = errors.New("Encountered logging type '-' with no type to exclude")
111
-	ErrLoggerFilenameMissing   = errors.New("Logging configuration specifies 'file' method but 'filename' is empty")
112
-	ErrLoggerHasNoTypes        = errors.New("Logger has no types to log")
113
-	ErrNetworkNameMissing      = errors.New("Network name missing")
114
-	ErrNoFingerprintOrPassword = errors.New("Fingerprint or password needs to be specified")
115
-	ErrNoListenersDefined      = errors.New("Server listening addresses missing")
116
-	ErrOperClassDependencies   = errors.New("OperClasses contains a looping dependency, or a class extends from a class that doesn't exist")
117
-	ErrServerNameMissing       = errors.New("Server name missing")
118
-	ErrServerNameNotHostname   = errors.New("Server name must match the format of a hostname")
119
-)

+ 1
- 1
irc/gateways.go Целия файл

@@ -55,7 +55,7 @@ func (wc *webircConfig) Populate() (err error) {
55 55
 	}
56 56
 
57 57
 	if wc.Certfp == "" && wc.PasswordString == "" {
58
-		return ErrNoFingerprintOrPassword
58
+		return errors.New("webirc block has no certfp or password specified")
59 59
 	}
60 60
 
61 61
 	wc.allowedNets, err = utils.ParseNetList(wc.Hosts)

Loading…
Отказ
Запис