Skip to content

Commit

Permalink
Merge pull request #3 from rebuy-de/add-must
Browse files Browse the repository at this point in the history
add cmdutil.Must
  • Loading branch information
svenwltr authored Apr 16, 2018
2 parents 83c9407 + 8e505e2 commit ca80dbe
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion cmdutil/exit.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
package cmdutil

import "os"
import (
"os"

log "github.com/sirupsen/logrus"
)

const (
mustExitCode = 1
)

type exitCode struct {
code int
Expand All @@ -27,3 +35,17 @@ func HandleExit() {
panic(e) // not an Exit, bubble up
}
}

// Must exits the application via Exit(1) and logs the error, if err does not
// equal nil. Additionally it logs the error with `%+v` to the debug log, so it
// can used together with github.com/pkg/errors to retrive more details about
// the error.
func Must(err error) {
if err == nil {
return
}

log.Debugf("%+v", err)
log.Error(err)
Exit(mustExitCode)
}

0 comments on commit ca80dbe

Please sign in to comment.