Skip to content

Commit

Permalink
plugins commands should exit with a non-zero code on error. Closes #980
Browse files Browse the repository at this point in the history
  • Loading branch information
pskrbasu committed Oct 5, 2021
1 parent c65e116 commit a087677
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cmd/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ func runPluginInstallCmd(cmd *cobra.Command, args []string) {
utils.LogTime("runPluginInstallCmd end")
if r := recover(); r != nil {
utils.ShowError(helpers.ToError(r))
exitCode = 1
}
}()

Expand All @@ -191,6 +192,7 @@ func runPluginInstallCmd(cmd *cobra.Command, args []string) {
fmt.Println()
cmd.Help()
fmt.Println()
exitCode = 2
return
}

Expand Down Expand Up @@ -261,6 +263,7 @@ func runPluginUpdateCmd(cmd *cobra.Command, args []string) {
utils.LogTime("runPluginUpdateCmd end")
if r := recover(); r != nil {
utils.ShowError(helpers.ToError(r))
exitCode = 1
}
}()
// args to 'plugin update' -- one or more plugins to install
Expand All @@ -274,6 +277,7 @@ func runPluginUpdateCmd(cmd *cobra.Command, args []string) {
fmt.Println()
cmd.Help()
fmt.Println()
exitCode = 2
return
}

Expand All @@ -284,19 +288,22 @@ func runPluginUpdateCmd(cmd *cobra.Command, args []string) {
fmt.Println()
cmd.Help()
fmt.Println()
exitCode = 2
return
}

state, err := statefile.LoadState()
if err != nil {
utils.ShowError(fmt.Errorf("could not load state"))
exitCode = 3
return
}

// load up the version file data
versionData, err := versionfile.LoadPluginVersionFile()
if err != nil {
utils.ShowError(fmt.Errorf("error loading current plugin data"))
exitCode = 3
return
}

Expand Down Expand Up @@ -350,6 +357,7 @@ func runPluginUpdateCmd(cmd *cobra.Command, args []string) {
// this happens if for some reason the update server could not be contacted,
// in which case we get back an empty map
utils.ShowError(fmt.Errorf("there was an issue contacting the update server. Please try later"))
exitCode = 3
return
}

Expand Down Expand Up @@ -454,18 +462,21 @@ func runPluginListCmd(*cobra.Command, []string) {
utils.LogTime("runPluginListCmd end")
if r := recover(); r != nil {
utils.ShowError(helpers.ToError(r))
exitCode = 1
}
}()
ctx := context.Background()
pluginConnectionMap, err := getPluginConnectionMap(ctx)
if err != nil {
utils.ShowErrorWithMessage(err, "Plugin Listing failed")
exitCode = 4
return
}

list, err := plugin.List(pluginConnectionMap)
if err != nil {
utils.ShowErrorWithMessage(err, "Plugin Listing failed")
exitCode = 4
}
headers := []string{"Name", "Version", "Connections"}
rows := [][]string{}
Expand All @@ -482,6 +493,7 @@ func runPluginUninstallCmd(cmd *cobra.Command, args []string) {
utils.LogTime("runPluginUninstallCmd end")
if r := recover(); r != nil {
utils.ShowError(helpers.ToError(r))
exitCode = 1
}
}()

Expand All @@ -491,12 +503,14 @@ func runPluginUninstallCmd(cmd *cobra.Command, args []string) {
fmt.Println()
cmd.Help()
fmt.Println()
exitCode = 2
return
}
ctx := context.Background()
connectionMap, err := getPluginConnectionMap(ctx)
if err != nil {
utils.ShowError(err)
exitCode = 4
return
}

Expand Down

0 comments on commit a087677

Please sign in to comment.