-
Notifications
You must be signed in to change notification settings - Fork 2k
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
ReadConfig(in io.Reader) does not Actually ReadConfig #1784
Comments
👋 Thanks for reporting! A maintainer will take a look at your issue shortly. 👀 In the meantime: We are working on Viper v2 and we would love to hear your thoughts about what you like or don't like about Viper, so we can improve or fix those issues. ⏰ If you have a couple minutes, please take some time and share your thoughts: https://forms.gle/R6faU74qPRPAzchZ9 📣 If you've already given us your feedback, you can still help by spreading the news, https://twitter.com/sagikazarmark/status/1306904078967074816 Thank you! ❤️ |
This seems to come up as a consequence of not specifying the config type. If you read in a file it still needs to be interpreted in some way and since the config type has not been set then See https://github.com/spf13/viper/blob/master/viper.go#L2218 I'll admit it is quirky behavior... perhaps adding a default case here https://github.com/spf13/viper/blob/master/viper.go#L1804 and retur an error would be more suitable since the function assumes that a config type has been set either explicitly using Either way, using |
I believe @mazenharake is correct. |
Added a check that returns an error when no config type is set. In the future it might make more sense to introduce an option to specify the type. |
Preflight Checklist
Viper Version
1.18.2
Go Version
1.22
Config Source
Files
Format
TOML
Repl.it link
No response
Code reproducing the issue
Expected Behavior
should read the config. When I print the config I expect the contents of the initial file. but I get {}
Actual Behavior
Return an empty config
Steps To Reproduce
No response
Additional Information
Did some initial debugging on this.
At this point all is well.
Here is where things start to hinky
Still dont have a file tto read? Ok says Viper Ill try to find the config file . . . But wait!
Here you can see that configPath has never been set. It still has not set the configFile or pconfigPath despite asking for a file reader that has the name and path of the file. The reult is that it cant find the config file and fails.
BUT!!!
This code works:
So why would I go through all that trouble to use
ReadConfig(f)when I could just go through the same trouble and use ReadInConfig()
?Seems like
ReadConfig(f)
should just ReadConfig fromf
The text was updated successfully, but these errors were encountered: