aboutsummaryrefslogtreecommitdiffstats
path: root/commands/env.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2021-05-09 11:33:20 +0200
committerMichael Muré <batolettre@gmail.com>2021-05-09 11:33:20 +0200
commit271dc1334cf8ce3c798dafeb9ac7113072195c93 (patch)
tree7b5e2bc96dacb4ea1ff36676c5a0dd904986e482 /commands/env.go
parenta75b27c4c6ad2fd91d247246f57c6323945c3095 (diff)
downloadgit-bug-271dc1334cf8ce3c798dafeb9ac7113072195c93.tar.gz
commands: proper backend close on RunE error
Diffstat (limited to 'commands/env.go')
-rw-r--r--commands/env.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/commands/env.go b/commands/env.go
index 8d12c5bf..ac7b789a 100644
--- a/commands/env.go
+++ b/commands/env.go
@@ -136,15 +136,23 @@ func loadBackendEnsureUser(env *Env) func(*cobra.Command, []string) error {
}
}
-// closeBackend is a post-run function that will close the backend properly
+// closeBackend is a wrapper for a RunE function that will close the backend properly
// if it has been opened.
-func closeBackend(env *Env) func(*cobra.Command, []string) error {
+// This wrapper style is necessary because a Cobra PostE function does not run if RunE return an error.
+func closeBackend(env *Env, runE func(cmd *cobra.Command, args []string) error) func(*cobra.Command, []string) error {
return func(cmd *cobra.Command, args []string) error {
+ errRun := runE(cmd, args)
+
if env.backend == nil {
return nil
}
err := env.backend.Close()
env.backend = nil
+
+ // prioritize the RunE error
+ if errRun != nil {
+ return errRun
+ }
return err
}
}