Skip to content

Commit

Permalink
Added line no in ini file read error info
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevatkm committed Jun 4, 2016
1 parent 3fa39f2 commit 85a1230
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions read.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package config

import (
"bufio"
"errors"
"fmt"
"os"
"strings"
"unicode"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}
}
Expand Down

0 comments on commit 85a1230

Please sign in to comment.