Skip to content

Commit

Permalink
Handle details of any type in core.PlatformUpgrade() status
Browse files Browse the repository at this point in the history
The status details of the function are used to identify the specific cause of a non-nil status. This is done via a type
assertion. Previously, this type assertion was configured such that a details of any type other than the expected would
result in a panic. At the moment, that will not occur because we only add details of one type. However, the whole point
of the type assertion is to support details of multiple types, and if other types are added a panic will not be the
appropriate behavior.

A better approach is to check the result of the type assertion, handling the non-nil status as a generic error if its
details are of a different type.
  • Loading branch information
per1234 authored and cmaglie committed Jul 13, 2021
1 parent 90068f4 commit adfa4a2
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions cli/core/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,14 @@ func runUpgradeCommand(cmd *cobra.Command, args []string) {
}

_, err := core.PlatformUpgrade(context.Background(), r, output.ProgressBar(), output.TaskProgress())
if d := err.Details(); len(d) > 0 && d[0].(*rpc.AlreadyAtLatestVersionError) != nil {
feedback.Printf("Platform %s is already at the latest version", platformRef)
} else if err != nil {
if err != nil {
if d := err.Details(); len(d) > 0 {
if _, ok := d[0].(*rpc.AlreadyAtLatestVersionError); ok {
feedback.Printf("Platform %s is already at the latest version", platformRef)
continue
}
}

feedback.Errorf("Error during upgrade: %v", err)
os.Exit(errorcodes.ErrGeneric)
}
Expand Down

0 comments on commit adfa4a2

Please sign in to comment.