From be71bf2fb25265f76d2e222df03def53bf3b695c Mon Sep 17 00:00:00 2001 From: ezekg Date: Tue, 26 Apr 2016 08:49:42 -0500 Subject: [PATCH] fail when config contains invalid yaml --- hound.go | 2 +- hound_test.go | 18 ++++++++++++++++++ main.go | 9 ++++++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/hound.go b/hound.go index bcee391..7667a79 100644 --- a/hound.go +++ b/hound.go @@ -33,7 +33,7 @@ func (h *Hound) New() bool { err = h.parseConfig(config) if err != nil { - return false + panic(err) } return true diff --git a/hound_test.go b/hound_test.go index 2eccd4f..f0c7a30 100644 --- a/hound_test.go +++ b/hound_test.go @@ -201,6 +201,24 @@ index 000000..000000 000000 t.Logf("Did pass") } } + + // Should fail when invalid Yaml is detected + { + badConfig := []byte(` + warn: + - 'string without a closing single quote + fail: + - 'some other string' + skip: + - '/bad.go + `) + + if err := hound.parseConfig(badConfig); err != nil { + t.Logf("Did not parse") + } else { + t.Fatalf("Should not parse") + } + } } func getDiff(t *testing.T, diffContents string) (string, *diff.Hunk) { diff --git a/main.go b/main.go index 0a3d4a9..4eecb75 100644 --- a/main.go +++ b/main.go @@ -13,7 +13,7 @@ import ( ) var ( - version = "0.5.2" + version = "0.5.3" showVersion = flag.Bool("v", false, "Show version") noColor = flag.Bool("no-color", false, "Disable color output") config = flag.String("config", ".githound.yml", "Hound config file") @@ -21,6 +21,13 @@ var ( ) func main() { + defer func() { + if r := recover(); r != nil { + color.Red(fmt.Sprintf("error: %s\n", r)) + os.Exit(1) + } + }() + flag.Parse() if *showVersion {