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

Provide documentation for ignoring "config file not found" error #719

Merged
merged 1 commit into from
Jul 13, 2019
Merged

Provide documentation for ignoring "config file not found" error #719

merged 1 commit into from
Jul 13, 2019

Conversation

lucperkins
Copy link
Contributor

@lucperkins lucperkins commented Jun 15, 2019

Previously, this PR contained a solution to the problem pointed out in issue #1 (namely a ReadInConfigIfExists() function. But I think that the solution shown in the comments of #1 is probably a better approach, so I've chosen to document that approach instead.

cc @sagikazarmark

@CLAassistant
Copy link

CLAassistant commented Jun 15, 2019

CLA assistant check
All committers have signed the CLA.

@lucperkins lucperkins changed the title Add ReadInConfigIfExists function Provide documentation for ignoring no config file Jun 22, 2019
@lucperkins lucperkins changed the title Provide documentation for ignoring no config file Provide documentation for ignoring Jun 22, 2019
@lucperkins lucperkins changed the title Provide documentation for ignoring Provide documentation for ignoring "config file not found" error Jun 22, 2019
@sagikazarmark
Copy link
Collaborator

Thanks @lucperkins!

@sagikazarmark sagikazarmark merged commit 5ae3a07 into spf13:master Jul 13, 2019
@fangpinsern
Copy link

Hi, I tried this solution and it does not seem to work. The error returned by err := viper.ReadInConfig() is an *fs.PathError error and not a viper.ConfigFileNotFoundError.

Though this is an old PR, google search on ignoring file not found leads me here. So just want to check if there is any new in built solutions to this issue?

Below is my code to initialize configurations

func InitializeConfig() {
	viper.SetConfigFile(".env")

	viper.AutomaticEnv()

	if err := viper.ReadInConfig(); err != nil {
		if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
			panic(fmt.Errorf("fatal error config file: %w", err))
		}
	}
}

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants