Skip to content

Commit

Permalink
feat: print config error
Browse files Browse the repository at this point in the history
  • Loading branch information
JanDeDobbeleer committed May 18, 2021
1 parent f54c9eb commit b623c5f
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/config.go
Expand Up @@ -33,6 +33,10 @@ const (
EnableHyperlink Property = "enable_hyperlink"
)

func printConfigError(err error) {
fmt.Println("Oh My Posh Error:\n", err.Error())
}

// GetConfig returns the default configuration including possible user overrides
func GetConfig(env environmentInfo) *Config {
cfg, err := loadConfig(env)
Expand All @@ -49,6 +53,7 @@ func loadConfig(env environmentInfo) (*Config, error) {
return nil, errors.New("NO CONFIG")
}
if _, err := os.Stat(configFile); os.IsNotExist(err) {
printConfigError(err)
return nil, errors.New("INVALID CONFIG PATH")
}

Expand All @@ -61,11 +66,13 @@ func loadConfig(env environmentInfo) (*Config, error) {

err := config.LoadFiles(configFile)
if err != nil {
printConfigError(err)
return nil, errors.New("UNABLE TO OPEN CONFIG")
}

err = config.BindStruct("", &cfg)
if err != nil {
printConfigError(err)
return nil, errors.New("INVALID CONFIG")
}

Expand All @@ -83,6 +90,7 @@ func exportConfig(configFile, format string) string {

err := config.LoadFiles(configFile)
if err != nil {
printConfigError(err)
return fmt.Sprintf("INVALID CONFIG:\n\n%s", err.Error())
}

Expand All @@ -96,6 +104,7 @@ func exportConfig(configFile, format string) string {
buf := new(bytes.Buffer)
_, err = config.DumpTo(buf, format)
if err != nil {
printConfigError(err)
return "UNABLE TO DUMP CONFIG"
}

Expand Down

0 comments on commit b623c5f

Please sign in to comment.