You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Theres no way to check for a "FileNotFound" error. godotenv panics as follows:
➜ server git:(master) ✗ go run main.go
panic: open .env: no such file or directory
goroutine 1 [running]:
main.main()
.../server/main.go:12 +0xa9
exit status 2
Possible Solution
A possible solution would be to enumerate errors:
var (
// EnvFileNotFound returns a "env file not found". Happens when godotenv is not able to find a .env file in the cwdEnvFileNotFound=errors.New("env file not found")
)
Then provide a ErrorIs like function, for example:
I think that does the work, but I'm more focused in something beyond this specific error. And improve error handling by using either an error variable or a handy function to discriminate the error type.
I imagine something like:
package error
// Error returned when GoDotEnv is unable to find the .env filevarEnvFileNotFounderror=errors.New(".env file not found")
// Checks if the error is a `EnvFileNotFound` errorfuncIsEnvFileNotFoundError(errerror) bool {
returnerr==EnvFileNotFound
}
Description
When running
gotdotenv.Load
:godotenv/godotenv.go
Line 41 in d6ee687
Theres no way to check for a "FileNotFound" error.
godotenv
panics as follows:Possible Solution
A possible solution would be to enumerate errors:
Then provide a
ErrorIs
like function, for example:Thanks in advance!
The text was updated successfully, but these errors were encountered: