Skip to content

Commit be71bf2

Browse files
committed
fail when config contains invalid yaml
1 parent 196ff6d commit be71bf2

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

hound.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (h *Hound) New() bool {
3333

3434
err = h.parseConfig(config)
3535
if err != nil {
36-
return false
36+
panic(err)
3737
}
3838

3939
return true

hound_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,24 @@ index 000000..000000 000000
201201
t.Logf("Did pass")
202202
}
203203
}
204+
205+
// Should fail when invalid Yaml is detected
206+
{
207+
badConfig := []byte(`
208+
warn:
209+
- 'string without a closing single quote
210+
fail:
211+
- 'some other string'
212+
skip:
213+
- '/bad.go
214+
`)
215+
216+
if err := hound.parseConfig(badConfig); err != nil {
217+
t.Logf("Did not parse")
218+
} else {
219+
t.Fatalf("Should not parse")
220+
}
221+
}
204222
}
205223

206224
func getDiff(t *testing.T, diffContents string) (string, *diff.Hunk) {

main.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,21 @@ import (
1313
)
1414

1515
var (
16-
version = "0.5.2"
16+
version = "0.5.3"
1717
showVersion = flag.Bool("v", false, "Show version")
1818
noColor = flag.Bool("no-color", false, "Disable color output")
1919
config = flag.String("config", ".githound.yml", "Hound config file")
2020
bin = flag.String("bin", "git", "Executable binary to use for git command")
2121
)
2222

2323
func main() {
24+
defer func() {
25+
if r := recover(); r != nil {
26+
color.Red(fmt.Sprintf("error: %s\n", r))
27+
os.Exit(1)
28+
}
29+
}()
30+
2431
flag.Parse()
2532

2633
if *showVersion {

0 commit comments

Comments
 (0)