Skip to content
This repository was archived by the owner on Jan 12, 2022. It is now read-only.

Commit 0ff0c0f

Browse files
committed
Propagate errors encountered when reading file
1 parent 4ed1339 commit 0ff0c0f

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

godotenv.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ func readFile(filename string) (envMap map[string]string, err error) {
143143
lines = append(lines, scanner.Text())
144144
}
145145

146+
if err = scanner.Err(); err != nil {
147+
return
148+
}
149+
146150
for _, fullLine := range lines {
147151
if !isIgnoredLine(fullLine) {
148152
key, value, err := parseLine(fullLine)

godotenv_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,12 @@ func TestLinesToIgnore(t *testing.T) {
269269
t.Error("ignoring a perfectly valid line to parse")
270270
}
271271
}
272+
273+
func TestErrorReadDirectory(t *testing.T) {
274+
envFileName := "fixtures/"
275+
envMap, err := Read(envFileName)
276+
277+
if err == nil {
278+
t.Errorf("Expected error, got %v", envMap)
279+
}
280+
}

0 commit comments

Comments
 (0)