Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Handle details of any type in core.PlatformUpgrade() status
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 Aug 28, 2021
commit c6b72b9c81e44ef2e9c03126be52dfe8b178e01a
13 changes: 9 additions & 4 deletions cli/core/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,15 @@ 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(tr("Platform %s is already at the latest version", platformRef))
} else if err != nil {
feedback.Errorf(tr("Error during upgrade: %v"), err)
if err != nil {
if d := err.Details(); len(d) > 0 {
if _, ok := d[0].(*rpc.AlreadyAtLatestVersionError); ok {
feedback.Printf(tr("Platform %s is already at the latest version", platformRef))
continue
}
}

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