@@ -17,8 +17,6 @@ package core
1717
1818import (
1919 "context"
20- "errors"
21- "fmt"
2220
2321 "github.com/arduino/arduino-cli/arduino/cores/packagemanager"
2422 "github.com/arduino/arduino-cli/commands"
@@ -27,12 +25,6 @@ import (
2725 "google.golang.org/grpc/status"
2826)
2927
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-
3628// PlatformUpgrade FIXMEDOC
3729func PlatformUpgrade (ctx context.Context , req * rpc.PlatformUpgradeRequest ,
3830 downloadCB commands.DownloadProgressCB , taskCB commands.TaskProgressCB ) (* rpc.PlatformUpgradeResponse , * status.Status ) {
@@ -48,7 +40,7 @@ func PlatformUpgrade(ctx context.Context, req *rpc.PlatformUpgradeRequest,
4840 PlatformArchitecture : req .Architecture ,
4941 }
5042 if err := upgradePlatform (pm , ref , downloadCB , taskCB , req .GetSkipPostInstall ()); err != nil {
51- return nil , status . Convert ( err )
43+ return nil , err
5244 }
5345
5446 status := commands .Init (& rpc.InitRequest {Instance : req .Instance }, nil )
@@ -61,33 +53,37 @@ func PlatformUpgrade(ctx context.Context, req *rpc.PlatformUpgradeRequest,
6153
6254func upgradePlatform (pm * packagemanager.PackageManager , platformRef * packagemanager.PlatformReference ,
6355 downloadCB commands.DownloadProgressCB , taskCB commands.TaskProgressCB ,
64- skipPostInstall bool ) error {
56+ skipPostInstall bool ) * status. Status {
6557 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" ))
6759 }
6860
6961 // Search the latest version for all specified platforms
7062 platform := pm .FindPlatform (platformRef )
7163 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 ) )
7365 }
7466 installed := pm .GetInstalledPlatformRelease (platform )
7567 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 ) )
7769 }
7870 latest := platform .GetLatestRelease ()
7971 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
8177 }
8278 platformRef .PlatformVersion = latest .Version
8379
8480 platformRelease , tools , err := pm .FindPlatformReleaseDependencies (platformRef )
8581 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 ) )
8783 }
8884 err = installPlatform (pm , platformRelease , tools , downloadCB , taskCB , skipPostInstall )
8985 if err != nil {
90- return err
86+ return status . Convert ( err )
9187 }
9288
9389 return nil
0 commit comments