Skip to content

Commit 3796d73

Browse files
committed
Implemented core commands return value management
1 parent b7fb8ce commit 3796d73

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

commands/core/download.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ func PlatformDownload(ctx context.Context, req *rpc.PlatformDownloadReq, progres
4848
formatter.PrintError(err, "Could not determine platform dependencies")
4949
return nil, fmt.Errorf("find platform dependencies error: %s", err)
5050
}
51-
downloadPlatform(pm, platform, progressCallback)
51+
err = downloadPlatform(pm, platform, progressCallback)
52+
if err != nil {
53+
formatter.PrintError(err, "Error Installing "+platform.String())
54+
return nil, err
55+
}
5256
for _, tool := range tools {
5357
err := downloadTool(pm, tool, progressCallback)
5458
if err != nil {

commands/core/install.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ func PlatformInstall(ctx context.Context, req *rpc.PlatformInstallReq) (*rpc.Pla
3232
return nil, fmt.Errorf("Could not determine platform dependencies", err)
3333
}
3434

35-
installPlatform(pm, platform, tools)
35+
err = installPlatform(pm, platform, tools)
36+
if err != nil {
37+
formatter.PrintError(err, "Error Installing "+platform.String())
38+
return nil, err
39+
}
3640

3741
return &rpc.PlatformInstallResp{}, nil
3842
}

commands/core/uninstall.go

+13-7
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func PlatformUninstall(ctx context.Context, req *rpc.PlatformUninstallReq) (*rpc
3434
version, err := semver.Parse(req.Version)
3535
if err != nil {
3636
formatter.PrintError(err, "version not readable")
37-
return fmt.Errorf("version not readable", err)
37+
return nil, fmt.Errorf("version not readable", err)
3838
}
3939
ref := &packagemanager.PlatformReference{
4040
Package: req.PlatformPackage,
@@ -45,13 +45,13 @@ func PlatformUninstall(ctx context.Context, req *rpc.PlatformUninstallReq) (*rpc
4545
platform := pm.FindPlatform(ref)
4646
if platform == nil {
4747
formatter.PrintErrorMessage("Platform not found " + ref.String())
48-
return fmt.Errorf("Platform not found "+ref.String(), err)
48+
return nil, fmt.Errorf("Platform not found "+ref.String(), err)
4949

5050
}
5151
platformRelease := pm.GetInstalledPlatformRelease(platform)
5252
if platformRelease == nil {
5353
formatter.PrintErrorMessage("Platform not installed " + ref.String())
54-
return fmt.Errorf("Platform not installed "+ref.String(), err)
54+
return nil, fmt.Errorf("Platform not installed "+ref.String(), err)
5555

5656
}
5757
ref.PlatformVersion = platformRelease.Version
@@ -60,11 +60,15 @@ func PlatformUninstall(ctx context.Context, req *rpc.PlatformUninstallReq) (*rpc
6060
platform, tools, err := pm.FindPlatformReleaseDependencies(ref)
6161
if err != nil {
6262
formatter.PrintError(err, "Could not determine platform dependencies")
63-
return fmt.Errorf("Could not determine platform dependencies", err)
63+
return nil, fmt.Errorf("Could not determine platform dependencies", err)
6464

6565
}
6666

67-
uninstallPlatformRelease(pm, platform)
67+
err = uninstallPlatformRelease(pm, platform)
68+
if err != nil {
69+
formatter.PrintError(err, "Error uninstalling "+platform.String())
70+
return nil, err
71+
}
6872

6973
for _, tool := range tools {
7074
if !pm.IsToolRequired(tool) {
@@ -75,7 +79,7 @@ func PlatformUninstall(ctx context.Context, req *rpc.PlatformUninstallReq) (*rpc
7579
return &rpc.PlatformUninstallResp{}, nil
7680
}
7781

78-
func uninstallPlatformRelease(pm *packagemanager.PackageManager, platformRelease *cores.PlatformRelease) {
82+
func uninstallPlatformRelease(pm *packagemanager.PackageManager, platformRelease *cores.PlatformRelease) error {
7983
log := pm.Log.WithField("platform", platformRelease)
8084

8185
log.Info("Uninstalling platform")
@@ -89,9 +93,10 @@ func uninstallPlatformRelease(pm *packagemanager.PackageManager, platformRelease
8993

9094
log.Info("Platform uninstalled")
9195
formatter.Print(platformRelease.String() + " uninstalled")
96+
return nil
9297
}
9398

94-
func uninstallToolRelease(pm *packagemanager.PackageManager, toolRelease *cores.ToolRelease) {
99+
func uninstallToolRelease(pm *packagemanager.PackageManager, toolRelease *cores.ToolRelease) error {
95100
log := pm.Log.WithField("Tool", toolRelease)
96101

97102
log.Info("Uninstalling tool")
@@ -105,4 +110,5 @@ func uninstallToolRelease(pm *packagemanager.PackageManager, toolRelease *cores.
105110

106111
log.Info("Tool uninstalled")
107112
formatter.Print(toolRelease.String() + " uninstalled")
113+
return nil
108114
}

0 commit comments

Comments
 (0)