Skip to content

Commit adfa4a2

Browse files
per1234cmaglie
authored andcommitted
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.
1 parent 90068f4 commit adfa4a2

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Diff for: cli/core/upgrade.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,14 @@ func runUpgradeCommand(cmd *cobra.Command, args []string) {
9494
}
9595

9696
_, err := core.PlatformUpgrade(context.Background(), r, output.ProgressBar(), output.TaskProgress())
97-
if d := err.Details(); len(d) > 0 && d[0].(*rpc.AlreadyAtLatestVersionError) != nil {
98-
feedback.Printf("Platform %s is already at the latest version", platformRef)
99-
} else if err != nil {
97+
if err != nil {
98+
if d := err.Details(); len(d) > 0 {
99+
if _, ok := d[0].(*rpc.AlreadyAtLatestVersionError); ok {
100+
feedback.Printf("Platform %s is already at the latest version", platformRef)
101+
continue
102+
}
103+
}
104+
100105
feedback.Errorf("Error during upgrade: %v", err)
101106
os.Exit(errorcodes.ErrGeneric)
102107
}

0 commit comments

Comments
 (0)