Skip to content

viper.ReadInConfig not returning ConfigFileNotFoundError if file is missing #1783

Open
@jeffdupont

Description

Preflight Checklist

  • I have searched the issue tracker for an issue that matches the one I want to file, without success.
  • I am not looking for support or already pursued the available support channels without success.
  • I have checked the troubleshooting guide for my problem, without success.

Viper Version

1.14.0

Go Version

1.22

Config Source

Files

Format

Dotenv

Repl.it link

No response

Code reproducing the issue

// load the environment configuration
	viper.SetConfigFile(".env")
	if err := viper.ReadInConfig(); err != nil {
		if _, ok := err.(viper.ConfigFileNotFoundError); ok {
			// Config file not found; ignore error if desired
		} else {
			// Config file was found but another error was produced
			log.WithError(err).Error("failed to read .env config file")
		}
	}

Expected Behavior

Expecting to skip over the error if the .env file is not present and instead fallback to the ENVVARS provided to the docker container

Actual Behavior

fails with error message

Steps To Reproduce

No response

Additional Information

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    kind/bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions