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 {
20
20
}
21
21
22
22
// 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
25
26
26
27
// CobraProvider is used to provide a Cobra command.
27
28
type CobraProvider interface {
@@ -42,7 +43,7 @@ func (a *App) ExecuteOrDie(options ...Option) {
42
43
if err == nil {
43
44
return
44
45
}
45
- if a .ErrorHandler == nil || ! a .ErrorHandler (err ) {
46
+ if a .ErrorHandler == nil || ! a .ErrorHandler (err , a . root ) {
46
47
a .defaultErrorHandler (err )
47
48
}
48
49
}
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ func TestExecuteOrDie(t *testing.T) {
24
24
commandline .WithExit (func (code int ) {
25
25
retcode = code
26
26
}),
27
- commandline .WithErrorHandler (func (merr error ) bool {
27
+ commandline .WithErrorHandler (func (merr error , _ * cobra. Command ) bool {
28
28
err = merr
29
29
return false
30
30
}),
You can’t perform that action at this time.
0 commit comments