From 85a123061070899a82f59c5ef6187e8fb4457f64 Mon Sep 17 00:00:00 2001 From: Jeevanandam M Date: Sat, 4 Jun 2016 12:41:56 -0700 Subject: [PATCH] Added line no in ini file read error info --- read.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/read.go b/read.go index 595d6d9..a1d5263 100644 --- a/read.go +++ b/read.go @@ -16,7 +16,7 @@ package config import ( "bufio" - "errors" + "fmt" "os" "strings" "unicode" @@ -58,8 +58,10 @@ func ReadDefault(fname string) (*Config, error) { func (c *Config) read(buf *bufio.Reader) (err error) { var section, option string var scanner = bufio.NewScanner(buf) + lineNo := 0 for scanner.Scan() { l := strings.TrimRightFunc(stripComments(scanner.Text()), unicode.IsSpace) + lineNo++ // Switch written for readability (not performance) switch { @@ -92,7 +94,7 @@ func (c *Config) read(buf *bufio.Reader) (err error) { c.AddOption(section, option, value) default: - return errors.New("could not parse line: " + l) + return fmt.Errorf("could not parse line #%v: %v", lineNo, l) } } }