bug(cmd): Ensure RunShutdownFuncs is called when an early error occurs (#2333)

* bug(cmd): Ensure RunShutdownFuncs is called when an early error occurs
This commit is contained in:
Louis Ruch authored and GitHub committed 2022-08-08 09:13:47 -07:00
1 parent 4d966c8eb4
commit dcccaf1bcf
4 files changed
+22 -12

No files matched your search

+6
View File
@@ -177,6 +177,12 @@ func (c *InitCommand) Run(args []string) (retCode int) {
return result
}
defer func() {
if err := c.RunShutdownFuncs(); err != nil {
c.UI.Error(fmt.Errorf("Error running shutdown tasks: %w", err).Error())
}
}()
if c.configWrapperCleanupFunc != nil {
defer func() {
if err := c.configWrapperCleanupFunc(); err != nil {
+6 -6
View File
@@ -382,6 +382,12 @@ func (c *Command) Run(args []string) int {
const op = "dev.(Command).Run"
c.CombineLogs = c.flagCombineLogs
defer func() {
if err := c.RunShutdownFuncs(); err != nil {
c.UI.Error(fmt.Errorf("Error running shutdown tasks: %w", err).Error())
}
}()
var err error
f := c.Flags()
@@ -615,12 +621,6 @@ func (c *Command) Run(args []string) int {
return base.CommandUserError
}
defer func() {
if err := c.RunShutdownFuncs(); err != nil {
c.UI.Error(fmt.Errorf("Error running shutdown tasks: %w", err).Error())
}
}()
var opts []base.Option
if c.flagCreateLoopbackHostPlugin {
c.DevLoopbackHostPluginId = "pl_1234567890"
+6 -6
View File
@@ -138,6 +138,12 @@ func (c *Command) AutocompleteFlags() complete.Flags {
func (c *Command) Run(args []string) int {
c.CombineLogs = c.flagCombineLogs
defer func() {
if err := c.RunShutdownFuncs(); err != nil {
c.UI.Error(fmt.Errorf("Error running shutdown tasks: %w", err).Error())
}
}()
if result := c.ParseFlagsAndConfig(args); result > 0 {
return result
}
@@ -471,12 +477,6 @@ func (c *Command) Run(args []string) int {
}
}
defer func() {
if err := c.RunShutdownFuncs(); err != nil {
c.UI.Error(fmt.Errorf("Error running shutdown tasks: %w", err).Error())
}
}()
if c.Config.Controller != nil {
c.EnabledPlugins = append(c.EnabledPlugins, base.EnabledPluginHostAws, base.EnabledPluginHostAzure)
if err := c.StartController(c.Context); err != nil {