Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass through errors encountered during usage of io.Reader #22

Merged
merged 1 commit into from
Apr 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions gotenv.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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