Skip to content

Commit

Permalink
Don't hide line parsing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mmilata committed Dec 12, 2016
1 parent 0ff0c0f commit 861984c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions fixtures/invalid1.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INVALID LINE
foo=bar
8 changes: 5 additions & 3 deletions godotenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,13 @@ func readFile(filename string) (envMap map[string]string, err error) {

for _, fullLine := range lines {
if !isIgnoredLine(fullLine) {
key, value, err := parseLine(fullLine)
var key, value string
key, value, err = parseLine(fullLine)

if err == nil {
envMap[key] = value
if err != nil {
return
}
envMap[key] = value
}
}
return
Expand Down
8 changes: 8 additions & 0 deletions godotenv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,11 @@ func TestErrorReadDirectory(t *testing.T) {
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)
}
}

0 comments on commit 861984c

Please sign in to comment.