Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ type App struct {
}

// ErrorHandler is a function that will be used to handle the errors. If true
// is returned, the default error handling will not be used.
type ErrorHandler func(err error) bool
// is returned, the default error handling will not be used. The Cobra's command
// passed to the error handler is the command that thrown the error.
type ErrorHandler func(err error, cmd *cobra.Command) bool

// CobraProvider is used to provide a Cobra command.
type CobraProvider interface {
Expand All @@ -42,7 +43,7 @@ func (a *App) ExecuteOrDie(options ...Option) {
if err == nil {
return
}
if a.ErrorHandler == nil || !a.ErrorHandler(err) {
if a.ErrorHandler == nil || !a.ErrorHandler(err, a.root) {
a.defaultErrorHandler(err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestExecuteOrDie(t *testing.T) {
commandline.WithExit(func(code int) {
retcode = code
}),
commandline.WithErrorHandler(func(merr error) bool {
commandline.WithErrorHandler(func(merr error, _ *cobra.Command) bool {
err = merr
return false
}),
Expand Down
Loading