From 8b74a98836a39819bcb763ef81787391383aa973 Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Fri, 18 Mar 2022 13:06:19 +0100 Subject: [PATCH] better error handling --- CHANGELOG.md | 6 ++++++ internal/config.go | 17 +++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f72ccb1..c689f60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.5.8] - 2022-03-18 + +### Fixed + +- Better error handling for bad config files. + ## [1.5.7] - 2022-03-11 ### Added diff --git a/internal/config.go b/internal/config.go index 6d45c4d..d290c7f 100644 --- a/internal/config.go +++ b/internal/config.go @@ -17,7 +17,7 @@ import ( "github.com/spf13/viper" ) -const VERSION = "1.5.7" +const VERSION = "1.5.8" type OptionMap map[string][]interface{} type Options map[string]OptionMap @@ -60,11 +60,16 @@ func GetConfig() *Config { colors.Faint.Println("Using env:\t", envFile) } } else { - cfgFileName := ".autorestic" - colors.Error.Println( - fmt.Sprintf( - "cannot find configuration file '%s.yml' or '%s.yaml'.", - cfgFileName, cfgFileName)) + text := err.Error() + if strings.Contains(text, "no such file or directory") { + cfgFileName := ".autorestic" + colors.Error.Println( + fmt.Sprintf( + "cannot find configuration file '%s.yml' or '%s.yaml'.", + cfgFileName, cfgFileName)) + } else { + colors.Error.Println("could not load config file\n" + text) + } os.Exit(1) }