3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-29 15:40:02 +01:00

Move config errors to call sites

Since allocating them is rare.
This commit is contained in:
Shivaram Lingamneni 2020-08-03 12:55:52 -04:00
parent 6a2fba9812
commit 9000383f88
3 changed files with 10 additions and 25 deletions

View File

@ -640,7 +640,7 @@ func (conf *Config) OperatorClasses() (map[string]*OperClass, error) {
lenOfLastOcs := -1 lenOfLastOcs := -1
for { for {
if lenOfLastOcs == len(ocs) { if lenOfLastOcs == len(ocs) {
return nil, ErrOperClassDependencies return nil, errors.New("OperClasses contains a looping dependency, or a class extends from a class that doesn't exist")
} }
lenOfLastOcs = len(ocs) lenOfLastOcs = len(ocs)
@ -869,24 +869,24 @@ func LoadConfig(filename string) (config *Config, err error) {
config.Filename = filename config.Filename = filename
if config.Network.Name == "" { if config.Network.Name == "" {
return nil, ErrNetworkNameMissing return nil, errors.New("Network name missing")
} }
if config.Server.Name == "" { if config.Server.Name == "" {
return nil, ErrServerNameMissing return nil, errors.New("Server name missing")
} }
if !utils.IsServerName(config.Server.Name) { if !utils.IsServerName(config.Server.Name) {
return nil, ErrServerNameNotHostname return nil, errors.New("Server name must match the format of a hostname")
} }
config.Server.nameCasefolded = strings.ToLower(config.Server.Name) config.Server.nameCasefolded = strings.ToLower(config.Server.Name)
if config.Datastore.Path == "" { if config.Datastore.Path == "" {
return nil, ErrDatastorePathMissing return nil, errors.New("Datastore path missing")
} }
//dan: automagically fix identlen until a few releases in the future (from now, 0.12.0), being a newly-introduced limit //dan: automagically fix identlen until a few releases in the future (from now, 0.12.0), being a newly-introduced limit
if config.Limits.IdentLen < 1 { if config.Limits.IdentLen < 1 {
config.Limits.IdentLen = 20 config.Limits.IdentLen = 20
} }
if config.Limits.NickLen < 1 || config.Limits.ChannelLen < 2 || config.Limits.AwayLen < 1 || config.Limits.KickLen < 1 || config.Limits.TopicLen < 1 { if config.Limits.NickLen < 1 || config.Limits.ChannelLen < 2 || config.Limits.AwayLen < 1 || config.Limits.KickLen < 1 || config.Limits.TopicLen < 1 {
return nil, ErrLimitsAreInsane return nil, errors.New("One or more limits values are too low")
} }
if config.Limits.RegistrationMessages == 0 { if config.Limits.RegistrationMessages == 0 {
config.Limits.RegistrationMessages = 1024 config.Limits.RegistrationMessages = 1024
@ -999,7 +999,7 @@ func LoadConfig(filename string) (config *Config, err error) {
} }
} }
if methods["file"] && logConfig.Filename == "" { if methods["file"] && logConfig.Filename == "" {
return nil, ErrLoggerFilenameMissing return nil, errors.New("Logging configuration specifies 'file' method but 'filename' is empty")
} }
logConfig.MethodFile = methods["file"] logConfig.MethodFile = methods["file"]
logConfig.MethodStdout = methods["stdout"] logConfig.MethodStdout = methods["stdout"]
@ -1018,7 +1018,7 @@ func LoadConfig(filename string) (config *Config, err error) {
continue continue
} }
if typeStr == "-" { if typeStr == "-" {
return nil, ErrLoggerExcludeEmpty return nil, errors.New("Encountered logging type '-' with no type to exclude")
} }
if typeStr[0] == '-' { if typeStr[0] == '-' {
typeStr = typeStr[1:] typeStr = typeStr[1:]
@ -1028,7 +1028,7 @@ func LoadConfig(filename string) (config *Config, err error) {
} }
} }
if len(logConfig.Types) < 1 { if len(logConfig.Types) < 1 {
return nil, ErrLoggerHasNoTypes return nil, errors.New("Logger has no types to log")
} }
newLogConfigs = append(newLogConfigs, logConfig) newLogConfigs = append(newLogConfigs, logConfig)

View File

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

View File

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