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

WriteConfig fails to write if file does not exist #433

Open
lllama opened this issue Jan 9, 2018 · 3 comments · May be fixed by #503 or #936
Open

WriteConfig fails to write if file does not exist #433

lllama opened this issue Jan 9, 2018 · 3 comments · May be fixed by #503 or #936

Comments

@lllama
Copy link

lllama commented Jan 9, 2018

The new WriteConfig function ends up calling findConfigFile, which in turn checks whether the file exists. If it doesn't then it returns an error, which stops the config being written.

@michaeleekk
Copy link

I had similar issue too and filed as #430 and right now my workaround is like this,

if err := viper.SafeWriteConfigAs(configPath); err != nil {
	if os.IsNotExist(err) {
		err = viper.WriteConfigAs(configPath)
	}
}

I'm just hoping there is a better solution.

@parkervcp
Copy link

Use WriteConfigAs which creates the file before writing.

@koooge
Copy link

koooge commented May 14, 2018

I got same issue.
I think WriteConfig should create configfile as same as WriteConfigAs if the file does not exist

@koooge koooge linked a pull request May 24, 2018 that will close this issue
yann-soubeyrand added a commit to yann-soubeyrand/viper that referenced this issue Jul 14, 2020
yann-soubeyrand added a commit to yann-soubeyrand/viper that referenced this issue Jul 14, 2020
yann-soubeyrand added a commit to yann-soubeyrand/viper that referenced this issue Jul 14, 2020
yann-soubeyrand added a commit to yann-soubeyrand/viper that referenced this issue Jul 14, 2020
@yann-soubeyrand yann-soubeyrand linked a pull request Jul 14, 2020 that will close this issue
jsuchome added a commit to jsuchome/fuseml-core that referenced this issue Jun 17, 2021
This is a workaround for spf13/viper#433;
once it is fixed, viper.WriteConfig should be able to create the config
file if it does not exist.
jsuchome added a commit to jsuchome/fuseml-core that referenced this issue Jun 17, 2021
This is a workaround for spf13/viper#433;
once it is fixed, viper.WriteConfig should be able to create the config
file if it does not exist.
jsuchome added a commit to jsuchome/fuseml-core that referenced this issue Jun 18, 2021
This is a workaround for spf13/viper#433;
once it is fixed, viper.WriteConfig should be able to create the config
file if it does not exist.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants