Skip to content

Commit

Permalink
Pass through errors encountered during usage of io.Reader (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bios-Marcel committed Apr 29, 2023
1 parent d2e64e6 commit 648c35b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gotenv.go
Expand Up @@ -209,6 +209,10 @@ func strictParse(r io.Reader, override bool) (Env, error) {
firstLine := true

for scanner.Scan() {
if err := scanner.Err(); err != nil {
return env, err
}

line := strings.TrimSpace(scanner.Text())

if firstLine {
Expand Down
15 changes: 15 additions & 0 deletions gotenv_test.go
Expand Up @@ -2,6 +2,8 @@ package gotenv_test

import (
"bufio"
"errors"
"io"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -240,6 +242,19 @@ func TestStrictParse(t *testing.T) {
}
}

type failingReader struct {
io.Reader
}

func (fr failingReader) Read(p []byte) (n int, err error) {
return 0, errors.New("you shall not read")
}

func TestStrictParse_PassThroughErrors(t *testing.T) {
_, err := gotenv.StrictParse(&failingReader{})
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 648c35b

Please sign in to comment.