config_file.go: return error if config is invalid

This commit is contained in:
Adhityaa 2018-06-21 21:03:32 +05:30
parent 4890bc4cc7
commit bb24f62b9c
2 changed files with 6 additions and 1 deletions

View File

@ -14,8 +14,11 @@ func configFileLoad(filepath string) error {
defer file.Close()
num := 0
scanner := bufio.NewScanner(file)
for scanner.Scan() {
num += 1
line := strings.TrimSpace(scanner.Text())
if line == "" {
continue
@ -27,7 +30,8 @@ func configFileLoad(filepath string) error {
i := strings.Index(line, "=")
if i == -1 {
continue
logger.Errorf("%s: line %d: neither a comment nor a valid setting", filepath, num)
return errorInvalidConfigFile
}
key := line[:i]

View File

@ -38,3 +38,4 @@ var errorNotADirectory = errors.New("The given path is not a directory.")
var errorGzip = errors.New("Cannot GZip content.")
var errorCannotDownloadDisqus = errors.New("We could not download your Disqus export file.")
var errorSelfVote = errors.New("You cannot vote on your own comment.")
var errorInvalidConfigFile = errors.New("Invalid config file.")