From 3c4b583feee724d8be4eee9ccda9f57443218143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dario=20Castan=CC=83e=CC=81?= Date: Tue, 18 Nov 2014 23:54:27 +0100 Subject: [PATCH] Action error shadowing avoided on After --- app.go | 12 ++++++++++-- app_test.go | 1 - 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app.go b/app.go index a125afc..25f49b0 100644 --- a/app.go +++ b/app.go @@ -120,7 +120,11 @@ func (a *App) Run(arguments []string) (err error) { if a.After != nil { 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 { defer func() { - err = a.After(context) + aferr := a.After(context) + // check Action error to avoid shadowing + if err == nil { + err = aferr + } }() } diff --git a/app_test.go b/app_test.go index 1e0b638..20978bd 100644 --- a/app_test.go +++ b/app_test.go @@ -396,7 +396,6 @@ func TestApp_AfterFunc(t *testing.T) { } } - func TestAppHelpPrinter(t *testing.T) { oldPrinter := cli.HelpPrinter defer func() {