File tree Expand file tree Collapse file tree 2 files changed +5
-4
lines changed
Expand file tree Collapse file tree 2 files changed +5
-4
lines changed Original file line number Diff line number Diff line change @@ -20,8 +20,9 @@ type App struct {
2020}
2121
2222// ErrorHandler is a function that will be used to handle the errors. If true
23- // is returned, the default error handling will not be used.
24- type ErrorHandler func (err error ) bool
23+ // is returned, the default error handling will not be used. The Cobra's command
24+ // passed to the error handler is the command that thrown the error.
25+ type ErrorHandler func (err error , cmd * cobra.Command ) bool
2526
2627// CobraProvider is used to provide a Cobra command.
2728type CobraProvider interface {
@@ -42,7 +43,7 @@ func (a *App) ExecuteOrDie(options ...Option) {
4243 if err == nil {
4344 return
4445 }
45- if a .ErrorHandler == nil || ! a .ErrorHandler (err ) {
46+ if a .ErrorHandler == nil || ! a .ErrorHandler (err , a . root ) {
4647 a .defaultErrorHandler (err )
4748 }
4849}
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ func TestExecuteOrDie(t *testing.T) {
2424 commandline .WithExit (func (code int ) {
2525 retcode = code
2626 }),
27- commandline .WithErrorHandler (func (merr error ) bool {
27+ commandline .WithErrorHandler (func (merr error , _ * cobra. Command ) bool {
2828 err = merr
2929 return false
3030 }),
You can’t perform that action at this time.
0 commit comments