Skip to content

Commit 8cfb004

Browse files
committed
fix: do not fail if a profile config is not present
1 parent 71056f6 commit 8cfb004

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

internal/pkg/profile/types.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package profile
22

33
import (
4-
"errors"
4+
"os"
55
"path"
66

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

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

4445
var config Config

0 commit comments

Comments
 (0)