From bb24f62b9ce24dfb26120b54b60f4e1ed1ca54d5 Mon Sep 17 00:00:00 2001 From: Adhityaa Date: Thu, 21 Jun 2018 21:03:32 +0530 Subject: [PATCH] config_file.go: return error if config is invalid --- api/config_file.go | 6 +++++- api/errors.go | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/api/config_file.go b/api/config_file.go index 01b99ae..1797054 100644 --- a/api/config_file.go +++ b/api/config_file.go @@ -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] diff --git a/api/errors.go b/api/errors.go index 408c9e8..223a3f3 100644 --- a/api/errors.go +++ b/api/errors.go @@ -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.")