feat: return error when no config type is set

Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
This commit is contained in:
Mark Sagi-Kazar 2024-06-05 12:35:27 +02:00 committed by Márk Sági-Kazár
parent afe3be23cb
commit a42c1b9f76

View file

@ -1577,6 +1577,10 @@ func (v *Viper) MergeInConfig() error {
func ReadConfig(in io.Reader) error { return v.ReadConfig(in) }
func (v *Viper) ReadConfig(in io.Reader) error {
if v.configType == "" {
return errors.New("cannot decode configuration: config type is not set")
}
v.config = make(map[string]any)
return v.unmarshalReader(in, v.config)
}
@ -1585,6 +1589,10 @@ func (v *Viper) ReadConfig(in io.Reader) error {
func MergeConfig(in io.Reader) error { return v.MergeConfig(in) }
func (v *Viper) MergeConfig(in io.Reader) error {
if v.configType == "" {
return errors.New("cannot decode configuration: config type is not set")
}
cfg := make(map[string]any)
if err := v.unmarshalReader(in, cfg); err != nil {
return err