Skip to content

Commit

Permalink
feat: return error when no config type is set
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
  • Loading branch information
sagikazarmark committed Jun 5, 2024
1 parent 05fdaa3 commit 736434a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
Expand Down

0 comments on commit 736434a

Please sign in to comment.