Skip to content

Commit

Permalink
add cmdutil.Must
Browse files Browse the repository at this point in the history
  • Loading branch information
svenwltr committed Apr 16, 2018
1 parent 83c9407 commit 8e505e2
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 8e505e2

Please sign in to comment.