1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Display a useful error message for custom configuration files

This commit is contained in:
Chris Cummer
2019-07-20 13:04:13 -07:00
parent ab94bd34ac
commit 5e18538f14
3 changed files with 26 additions and 9 deletions

View File

@@ -140,12 +140,17 @@ func CreateFile(fileName string) (string, error) {
}
// LoadWtfConfigFile loads the config.yml file to configure the app
func LoadWtfConfigFile(filePath string) *config.Config {
func LoadWtfConfigFile(filePath string, isCustomConfig bool) *config.Config {
absPath, _ := expandHomeDir(filePath)
cfg, err := config.ParseYamlFile(absPath)
if err != nil {
displayWtfConfigFileLoadError(err)
if isCustomConfig {
displayWtfCustomConfigFileLoadError(err)
} else {
displayWtfConfigFileLoadError(err)
}
os.Exit(1)
}
@@ -242,6 +247,17 @@ func displayWtfConfigFileLoadError(err error) {
fmt.Printf("Error: \033[0;31m%s\033[0m\n\n", err.Error())
}
func displayWtfCustomConfigFileLoadError(err error) {
fmt.Println("\n\033[1mERROR:\033[0m Could not load '\033[0;33mconfig.yml\033[0m'.")
fmt.Println()
fmt.Println("This could mean one of two things:")
fmt.Println()
fmt.Println(" 1. That file doesn't exist.")
fmt.Println(" 2. That file has a YAML syntax error. Try running it through http://www.yamllint.com to check for errors.")
fmt.Println()
fmt.Printf("Error: \033[0;31m%s\033[0m\n\n", err.Error())
}
// Expand expands the path to include the home directory if the path
// is prefixed with `~`. If it isn't prefixed with `~`, the path is
// returned as-is.