Browse Source

Catch errors in main function

renovate/configure
Yota Toyama 8 years ago
parent
commit
bc31a523fa
  1. 5
      examples/error.feature
  2. 10
      main.go

5
examples/error.feature

@ -0,0 +1,5 @@
Feature: Error
Scenario: Fail with no argument
Given a file named "foo.md" with ""
When I run `linkcheck`
Then the exit status should be 1

10
main.go

@ -8,6 +8,13 @@ import (
) )
func main() { func main() {
defer func() {
if r := recover(); r != nil {
fmt.Fprintln(os.Stderr, r.(error).Error())
os.Exit(1)
}
}()
getArgs() getArgs()
} }
@ -20,8 +27,7 @@ Usage:
args, err := docopt.Parse(usage, nil, true, "linkcheck", true) args, err := docopt.Parse(usage, nil, true, "linkcheck", true)
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, err.Error()) panic(err)
os.Exit(1)
} }
return args return args

Loading…
Cancel
Save