forked from coop-cloud-mirrors/godotenv
Don't hide line parsing errors
This commit is contained in:
2
fixtures/invalid1.env
Normal file
2
fixtures/invalid1.env
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
INVALID LINE
|
||||||
|
foo=bar
|
@ -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
|
||||||
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user