@@ -17,8 +17,6 @@ package core
17
17
18
18
import (
19
19
"context"
20
- "errors"
21
- "fmt"
22
20
23
21
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
24
22
"github.com/arduino/arduino-cli/commands"
@@ -27,12 +25,6 @@ import (
27
25
"google.golang.org/grpc/status"
28
26
)
29
27
30
- var (
31
- // ErrAlreadyLatest is returned when an upgrade is not possible because
32
- // already at latest version.
33
- ErrAlreadyLatest = errors .New (tr ("platform already at latest version" ))
34
- )
35
-
36
28
// PlatformUpgrade FIXMEDOC
37
29
func PlatformUpgrade (ctx context.Context , req * rpc.PlatformUpgradeRequest ,
38
30
downloadCB commands.DownloadProgressCB , taskCB commands.TaskProgressCB ) (* rpc.PlatformUpgradeResponse , * status.Status ) {
@@ -48,7 +40,7 @@ func PlatformUpgrade(ctx context.Context, req *rpc.PlatformUpgradeRequest,
48
40
PlatformArchitecture : req .Architecture ,
49
41
}
50
42
if err := upgradePlatform (pm , ref , downloadCB , taskCB , req .GetSkipPostInstall ()); err != nil {
51
- return nil , status . Convert ( err )
43
+ return nil , err
52
44
}
53
45
54
46
status := commands .Init (& rpc.InitRequest {Instance : req .Instance }, nil )
@@ -61,33 +53,37 @@ func PlatformUpgrade(ctx context.Context, req *rpc.PlatformUpgradeRequest,
61
53
62
54
func upgradePlatform (pm * packagemanager.PackageManager , platformRef * packagemanager.PlatformReference ,
63
55
downloadCB commands.DownloadProgressCB , taskCB commands.TaskProgressCB ,
64
- skipPostInstall bool ) error {
56
+ skipPostInstall bool ) * status. Status {
65
57
if platformRef .PlatformVersion != nil {
66
- return fmt . Errorf ( tr ("upgrade doesn't accept parameters with version" ))
58
+ return status . New ( codes . InvalidArgument , tr ("Upgrade doesn't accept parameters with version" ))
67
59
}
68
60
69
61
// Search the latest version for all specified platforms
70
62
platform := pm .FindPlatform (platformRef )
71
63
if platform == nil {
72
- return fmt . Errorf ( tr ("platform %s not found" ) , platformRef )
64
+ return status . Newf ( codes . InvalidArgument , tr ("Platform %s not found" , platformRef ) )
73
65
}
74
66
installed := pm .GetInstalledPlatformRelease (platform )
75
67
if installed == nil {
76
- return fmt . Errorf ( tr ("platform %s is not installed" ) , platformRef )
68
+ return status . Newf ( codes . InvalidArgument , tr ("Platform %s is not installed" , platformRef ) )
77
69
}
78
70
latest := platform .GetLatestRelease ()
79
71
if ! latest .Version .GreaterThan (installed .Version ) {
80
- return ErrAlreadyLatest
72
+ status , e := status .New (codes .AlreadyExists , "platform already at latest version" ).WithDetails (& rpc.AlreadyAtLatestVersionError {})
73
+ if e != nil { // should never happen
74
+ panic (e )
75
+ }
76
+ return status
81
77
}
82
78
platformRef .PlatformVersion = latest .Version
83
79
84
80
platformRelease , tools , err := pm .FindPlatformReleaseDependencies (platformRef )
85
81
if err != nil {
86
- return fmt . Errorf ( tr ("platform %s is not installed" ) , platformRef )
82
+ return status . Newf ( codes . FailedPrecondition , tr ("Platform %s is not installed" , platformRef ) )
87
83
}
88
84
err = installPlatform (pm , platformRelease , tools , downloadCB , taskCB , skipPostInstall )
89
85
if err != nil {
90
- return err
86
+ return status . Convert ( err )
91
87
}
92
88
93
89
return nil
0 commit comments