Skip to content

Commit

Permalink
fix: do not fail if a profile config is not present
Browse files Browse the repository at this point in the history
  • Loading branch information
mworzala committed Sep 15, 2023
1 parent 71056f6 commit 8cfb004
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions internal/pkg/profile/types.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package profile

import (
"errors"
"os"
"path"

"github.com/spf13/viper"
Expand Down Expand Up @@ -35,10 +35,11 @@ func (p *Profile) Config() *Config {
v := viper.New()
v.SetConfigFile(path.Join(p.Directory, "config.json"))

err := v.ReadInConfig()
if err != nil && !errors.As(err, &viper.ConfigFileNotFoundError{}) {
// For some reason viper doesnt implement Is() for ConfigFileNotFoundError
panic(err) //todo
// Read the config file if it exists
if _, err := os.Stat(v.ConfigFileUsed()); err == nil {
if err := v.ReadInConfig(); err != nil {
panic(err) //todo this should proceed with default config and log an error
}
}

var config Config
Expand Down

0 comments on commit 8cfb004

Please sign in to comment.