Don't hide line parsing errors

This commit is contained in:
Martin Milata
2016-12-12 14:43:30 +01:00
parent 0ff0c0fc7a
commit 861984c215
3 changed files with 15 additions and 3 deletions

2
fixtures/invalid1.env Normal file
View File

@ -0,0 +1,2 @@
INVALID LINE
foo=bar

View File

@ -149,11 +149,13 @@ func readFile(filename string) (envMap map[string]string, err error) {
for _, fullLine := range lines { for _, fullLine := range lines {
if !isIgnoredLine(fullLine) { if !isIgnoredLine(fullLine) {
key, value, err := parseLine(fullLine) var key, value string
key, value, err = parseLine(fullLine)
if err == nil { if err != nil {
envMap[key] = value return
} }
envMap[key] = value
} }
} }
return return

View File

@ -278,3 +278,11 @@ func TestErrorReadDirectory(t *testing.T) {
t.Errorf("Expected error, got %v", envMap) t.Errorf("Expected error, got %v", envMap)
} }
} }
func TestErrorParsing(t *testing.T) {
envFileName := "fixtures/invalid1.env"
envMap, err := Read(envFileName)
if err == nil {
t.Errorf("Expected error, got %v", envMap)
}
}