Skip to content

Commit 98c63ed

Browse files
franklinkimsagikazarmark
authored andcommitted
feat: check providers and log error
1 parent 1bc0a5a commit 98c63ed

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

viper.go

+14
Original file line numberDiff line numberDiff line change
@@ -1870,6 +1870,10 @@ func (v *Viper) getKeyValueConfig() error {
18701870
return RemoteConfigError("Enable the remote features by doing a blank import of the viper/remote package: '_ github.com/spf13/viper/remote'")
18711871
}
18721872

1873+
if len(v.remoteProviders) == 0 {
1874+
return RemoteConfigError("No Remote Providers")
1875+
}
1876+
18731877
for _, rp := range v.remoteProviders {
18741878
val, err := v.getRemoteConfig(rp)
18751879
if err != nil {
@@ -1896,6 +1900,10 @@ func (v *Viper) getRemoteConfig(provider RemoteProvider) (map[string]interface{}
18961900

18971901
// Retrieve the first found remote configuration.
18981902
func (v *Viper) watchKeyValueConfigOnChannel() error {
1903+
if len(v.remoteProviders) == 0 {
1904+
return RemoteConfigError("No Remote Providers")
1905+
}
1906+
18991907
for _, rp := range v.remoteProviders {
19001908
respc, _ := RemoteConfig.WatchChannel(rp)
19011909
// Todo: Add quit channel
@@ -1913,9 +1921,15 @@ func (v *Viper) watchKeyValueConfigOnChannel() error {
19131921

19141922
// Retrieve the first found remote configuration.
19151923
func (v *Viper) watchKeyValueConfig() error {
1924+
if len(v.remoteProviders) == 0 {
1925+
return RemoteConfigError("No Remote Providers")
1926+
}
1927+
19161928
for _, rp := range v.remoteProviders {
19171929
val, err := v.watchRemoteConfig(rp)
19181930
if err != nil {
1931+
v.logger.Error(fmt.Errorf("watch remote config: %w", err).Error())
1932+
19191933
continue
19201934
}
19211935
v.kvstore = val

0 commit comments

Comments
 (0)