Skip to content

Commit

Permalink
Fix: pass through scanner errors when no line is read (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
arroyoh authored Aug 11, 2023
1 parent 648c35b commit 266f68a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gotenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func strictParse(r io.Reader, override bool) (Env, error) {
}
}

return env, nil
return env, scanner.Err()
}

var (
Expand Down
13 changes: 13 additions & 0 deletions gotenv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,19 @@ func TestStrictParse_PassThroughErrors(t *testing.T) {
assert.Error(t, err)
}

type infiniteReader struct {
io.Reader
}

func (er infiniteReader) Read(p []byte) (n int, err error) {
return len(p), nil
}

func TestStrictParse_NoTokenPassThroughErrors(t *testing.T) {
_, err := gotenv.StrictParse(&infiniteReader{})
assert.Error(t, err)
}

func TestRead(t *testing.T) {
for _, tt := range fixtures {
env, err := gotenv.Read(tt.filename)
Expand Down

0 comments on commit 266f68a

Please sign in to comment.