Skip to content

Commit

Permalink
Cleaned up the error messagesi for reading configuration file
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasbn committed Mar 5, 2023
1 parent 12630c7 commit 079b553
Showing 1 changed file with 19 additions and 28 deletions.
47 changes: 19 additions & 28 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func realMain() int {
ignoreObject, err = ignore.CompileIgnoreFile(config.Ignorefile)

if err != nil {
fmt.Printf("unable to read %s file", config.Ignorefile)
fmt.Printf("unable to read %s file\n", config.Ignorefile)
return 1
}
}
Expand Down Expand Up @@ -324,35 +324,26 @@ func loadConfigFile(configFile string, config *Config) (rv bool, err error) {

jsonData, err := os.ReadFile(configFile)

if json.Valid([]byte(jsonData)) {

if err != nil {
fmt.Printf("unable to read %s file, ignoring - %v\n", configFile, err)
}

err = json.Unmarshal(jsonData, &config)
if err != nil {
fmt.Println("error unmarshalling JSON configuration:", err)
}
if err != nil {
return false, err
}

if err != nil {
return false, err
}
err = json.Unmarshal(jsonData, &config)
if err != nil {
return false, err
}

if config.Debug {
fmt.Println("Config file:")
fmt.Println("\tcolor: ", config.Color)
fmt.Println("\tnocolor: ", config.Nocolor)
fmt.Println("\tignorefile: ", config.Ignorefile)
fmt.Println("\tdebug: ", config.Debug)
fmt.Println("\tverbose: ", config.Verbose)
fmt.Println("\texcluded: ", config.Excluded)
fmt.Println("\tincluded: ", config.Included)
fmt.Println("\tfullpath: ", config.Fullpath)
fmt.Println("\tnofullpath: ", config.Nofullpath)
}
} else {
return false, fmt.Errorf("Config file %s does not contain valid JSON", configFile)
if config.Debug {
fmt.Println("Config file:")
fmt.Println("\tcolor: ", config.Color)
fmt.Println("\tnocolor: ", config.Nocolor)
fmt.Println("\tignorefile: ", config.Ignorefile)
fmt.Println("\tdebug: ", config.Debug)
fmt.Println("\tverbose: ", config.Verbose)
fmt.Println("\texcluded: ", config.Excluded)
fmt.Println("\tincluded: ", config.Included)
fmt.Println("\tfullpath: ", config.Fullpath)
fmt.Println("\tnofullpath: ", config.Nofullpath)
}
} else {
return false, fmt.Errorf("Config file %s not found", configFile)
Expand Down

0 comments on commit 079b553

Please sign in to comment.