Skip to content

Commit

Permalink
Fix panic at dotenv (over)loading
Browse files Browse the repository at this point in the history
  • Loading branch information
roeldev committed Apr 6, 2024
1 parent 60ae23f commit ece06ff
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
14 changes: 2 additions & 12 deletions dotenv/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,26 @@ import (
"io/fs"
)

const panicNilFsys = "dotenv: fs.FS must not be nil"

// Load sets the environment variables from the active environment using
// env.Load.
func Load(dir string, ae ActiveEnvironment) error {
return env.Load(ReadFS(nil, dir, ae))
return env.Load(Read(dir, ae))
}

// Overload sets and overwrites the environment variables from the active
// environment using env.Overload.
func Overload(dir string, ae ActiveEnvironment) error {
return env.Overload(ReadFS(nil, dir, ae))
return env.Overload(Read(dir, ae))
}

// LoadFS sets the environment variables from the active environment using
// env.Load.
func LoadFS(fsys fs.FS, dir string, ae ActiveEnvironment) error {
if fsys == nil {
panic(panicNilFsys)
}

return env.Load(ReadFS(fsys, dir, ae))
}

// OverloadFS sets and overwrites the environment variables from the active
// environment using env.Overload.
func OverloadFS(fsys fs.FS, dir string, ae ActiveEnvironment) error {
if fsys == nil {
panic(panicNilFsys)
}

return env.Overload(ReadFS(fsys, dir, ae))
}
2 changes: 2 additions & 0 deletions dotenv/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ func Read(dir string, ae ActiveEnvironment) *Reader {
return newReader(nil, dir, ae)
}

const panicNilFsys = "dotenv: fs.FS must not be nil"

// ReadFS reads .env files at dir from fsys, depending on the provided
// ActiveEnvironment.
func ReadFS(fsys fs.FS, dir string, ae ActiveEnvironment) *Reader {
Expand Down

0 comments on commit ece06ff

Please sign in to comment.