Action error shadowing avoided on After

This commit is contained in:
Dario Castañé 2014-11-18 23:54:27 +01:00
parent 44efc2952d
commit 3c4b583fee
2 changed files with 10 additions and 3 deletions

12
app.go
View File

@ -120,7 +120,11 @@ func (a *App) Run(arguments []string) (err error) {
if a.After != nil { if a.After != nil {
defer func() { defer func() {
err = a.After(context) aferr := a.After(context)
// check Action error to avoid shadowing
if err == nil {
err = aferr
}
}() }()
} }
@ -208,7 +212,11 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) {
if a.After != nil { if a.After != nil {
defer func() { defer func() {
err = a.After(context) aferr := a.After(context)
// check Action error to avoid shadowing
if err == nil {
err = aferr
}
}() }()
} }

View File

@ -396,7 +396,6 @@ func TestApp_AfterFunc(t *testing.T) {
} }
} }
func TestAppHelpPrinter(t *testing.T) { func TestAppHelpPrinter(t *testing.T) {
oldPrinter := cli.HelpPrinter oldPrinter := cli.HelpPrinter
defer func() { defer func() {