Skip to content

Commit b08a2aa

Browse files
committed
HandleError is dead, long live ConvertToTranslatableError!
- replaced PluginInstallationCancelled with boolean return - adjusted InvalidSSLCertError to match UnverifiedServerError - adjust integration test for ApplicationNotFoundError
1 parent b722691 commit b08a2aa

File tree

159 files changed

+837
-1030
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

159 files changed

+837
-1030
lines changed

command/common/install_plugin_command.go

+20-21
Original file line numberDiff line numberDiff line change
@@ -77,36 +77,36 @@ func (cmd *InstallPluginCommand) Setup(config command.Config, ui command.UI) err
7777
func (cmd InstallPluginCommand) Execute([]string) error {
7878
err := os.MkdirAll(cmd.Config.PluginHome(), 0700)
7979
if err != nil {
80-
return shared.HandleError(err)
80+
return err
8181
}
8282

8383
tempPluginDir, err := ioutil.TempDir(cmd.Config.PluginHome(), "temp")
8484
defer os.RemoveAll(tempPluginDir)
8585

8686
if err != nil {
87-
return shared.HandleError(err)
87+
return err
8888
}
8989

9090
tempPluginPath, pluginSource, err := cmd.getPluginBinaryAndSource(tempPluginDir)
9191
if err != nil {
92-
return shared.HandleError(err)
92+
return err
9393
}
9494

9595
// copy twice when downloading from a URL to keep Windows specific code
9696
// isolated to CreateExecutableCopy
9797
executablePath, err := cmd.Actor.CreateExecutableCopy(tempPluginPath, tempPluginDir)
9898
if err != nil {
99-
return shared.HandleError(err)
99+
return err
100100
}
101101

102102
rpcService, err := shared.NewRPCService(cmd.Config, cmd.UI)
103103
if err != nil {
104-
return shared.HandleError(err)
104+
return err
105105
}
106106

107107
plugin, err := cmd.Actor.GetAndValidatePlugin(rpcService, Commands, executablePath)
108108
if err != nil {
109-
return shared.HandleError(err)
109+
return err
110110
}
111111

112112
if cmd.Actor.IsPluginInstalled(plugin.Name) {
@@ -120,7 +120,7 @@ func (cmd InstallPluginCommand) Execute([]string) error {
120120

121121
err = cmd.uninstallPlugin(plugin, rpcService)
122122
if err != nil {
123-
return shared.HandleError(err)
123+
return err
124124
}
125125
}
126126

@@ -256,23 +256,21 @@ func (InstallPluginCommand) handleFetchingPluginInfoFromRepositoriesError(fetchE
256256
}
257257

258258
func (cmd InstallPluginCommand) getPluginFromLocalFile(pluginLocation string) (string, PluginSource, error) {
259-
err := cmd.installPluginPrompt(installConfirmationPrompt, map[string]interface{}{
259+
exitInstall, err := cmd.installPluginPrompt(installConfirmationPrompt, map[string]interface{}{
260260
"Path": pluginLocation,
261261
})
262-
if err != nil {
262+
if err != nil || exitInstall {
263263
return "", 0, err
264264
}
265265

266266
return pluginLocation, PluginFromLocalFile, err
267267
}
268268

269269
func (cmd InstallPluginCommand) getPluginFromURL(pluginLocation string, tempPluginDir string) (string, PluginSource, error) {
270-
var err error
271-
272-
err = cmd.installPluginPrompt(installConfirmationPrompt, map[string]interface{}{
270+
exitInstall, err := cmd.installPluginPrompt(installConfirmationPrompt, map[string]interface{}{
273271
"Path": pluginLocation,
274272
})
275-
if err != nil {
273+
if err != nil || exitInstall {
276274
return "", 0, err
277275
}
278276

@@ -311,23 +309,24 @@ func (cmd InstallPluginCommand) getPluginFromRepositories(pluginName string, rep
311309
})
312310

313311
installedPlugin, exist := cmd.Config.GetPlugin(pluginName)
312+
var exitInstall bool
314313
if exist {
315314
cmd.UI.DisplayText("Plugin {{.PluginName}} {{.PluginVersion}} is already installed.", map[string]interface{}{
316315
"PluginName": installedPlugin.Name,
317316
"PluginVersion": installedPlugin.Version.String(),
318317
})
319318

320-
err = cmd.installPluginPrompt("Do you want to uninstall the existing plugin and install {{.Path}} {{.PluginVersion}}?", map[string]interface{}{
319+
exitInstall, err = cmd.installPluginPrompt("Do you want to uninstall the existing plugin and install {{.Path}} {{.PluginVersion}}?", map[string]interface{}{
321320
"Path": pluginName,
322321
"PluginVersion": pluginInfo.Version,
323322
})
324323
} else {
325-
err = cmd.installPluginPrompt(installConfirmationPrompt, map[string]interface{}{
324+
exitInstall, err = cmd.installPluginPrompt(installConfirmationPrompt, map[string]interface{}{
326325
"Path": pluginName,
327326
})
328327
}
329328

330-
if err != nil {
329+
if err != nil || exitInstall {
331330
return "", 0, err
332331
}
333332

@@ -347,12 +346,12 @@ func (cmd InstallPluginCommand) getPluginFromRepositories(pluginName string, rep
347346
return tempPath, PluginFromRepository, err
348347
}
349348

350-
func (cmd InstallPluginCommand) installPluginPrompt(template string, templateValues ...map[string]interface{}) error {
349+
func (cmd InstallPluginCommand) installPluginPrompt(template string, templateValues ...map[string]interface{}) (bool, error) {
351350
cmd.UI.DisplayHeader("Attention: Plugins are binaries written by potentially untrusted authors.")
352351
cmd.UI.DisplayHeader("Install and use plugins at your own risk.")
353352

354353
if cmd.Force {
355-
return nil
354+
return false, nil
356355
}
357356

358357
var (
@@ -363,13 +362,13 @@ func (cmd InstallPluginCommand) installPluginPrompt(template string, templateVal
363362
really, promptErr = cmd.UI.DisplayBoolPrompt(false, template, templateValues...)
364363

365364
if promptErr != nil {
366-
return promptErr
365+
return false, promptErr
367366
}
368367

369368
if !really {
370369
cmd.UI.DisplayText("Plugin installation cancelled.")
371-
return shared.PluginInstallationCancelled{}
370+
return true, nil
372371
}
373372

374-
return nil
373+
return false, nil
375374
}

command/common/install_plugin_command_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ var _ = Describe("install-plugin command", func() {
100100
})
101101

102102
It("returns an error", func() {
103-
Expect(executeErr).To(MatchError(translatableerror.PluginInvalidError{}))
103+
Expect(executeErr).To(MatchError(returnedErr))
104104

105105
Expect(testUI.Out).ToNot(Say("Installing plugin"))
106106
})
@@ -115,7 +115,7 @@ var _ = Describe("install-plugin command", func() {
115115
})
116116

117117
It("returns an error", func() {
118-
Expect(executeErr).To(MatchError(translatableerror.PluginInvalidError{Err: wrappedErr}))
118+
Expect(executeErr).To(MatchError(actionerror.PluginInvalidError{Err: wrappedErr}))
119119

120120
Expect(testUI.Out).ToNot(Say("Installing plugin"))
121121
})
@@ -454,7 +454,7 @@ var _ = Describe("install-plugin command", func() {
454454
})
455455

456456
It("returns a DownloadPluginHTTPError", func() {
457-
Expect(executeErr).To(MatchError(translatableerror.DownloadPluginHTTPError{Message: "some-status"}))
457+
Expect(executeErr).To(MatchError(pluginerror.RawHTTPStatusError{Status: "some-status"}))
458458
})
459459
})
460460

@@ -464,7 +464,7 @@ var _ = Describe("install-plugin command", func() {
464464
})
465465

466466
It("returns a DownloadPluginHTTPError", func() {
467-
Expect(executeErr).To(MatchError(translatableerror.DownloadPluginHTTPError{Message: "x509: certificate signed by unknown authority"}))
467+
Expect(executeErr).To(MatchError(pluginerror.UnverifiedServerError{}))
468468
})
469469
})
470470
})
@@ -503,7 +503,7 @@ var _ = Describe("install-plugin command", func() {
503503
})
504504

505505
It("returns an error", func() {
506-
Expect(executeErr).To(MatchError(translatableerror.PluginInvalidError{}))
506+
Expect(executeErr).To(MatchError(returnedErr))
507507

508508
Expect(fakeActor.IsPluginInstalledCallCount()).To(Equal(0))
509509
})

command/common/install_plugin_from_repo_command_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ var _ = Describe("install-plugin command", func() {
9393
})
9494

9595
It("returns a RepositoryNotRegisteredError", func() {
96-
Expect(executeErr).To(MatchError(translatableerror.RepositoryNotRegisteredError{Name: repoName}))
96+
Expect(executeErr).To(MatchError(actionerror.RepositoryNotRegisteredError{Name: repoName}))
9797

9898
Expect(fakeActor.GetPluginRepositoryCallCount()).To(Equal(1))
9999
repositoryNameArg := fakeActor.GetPluginRepositoryArgsForCall(0)
@@ -118,7 +118,7 @@ var _ = Describe("install-plugin command", func() {
118118
})
119119

120120
It("returns a JSONSyntaxError", func() {
121-
Expect(executeErr).To(MatchError(translatableerror.JSONSyntaxError{Err: jsonErr}))
121+
Expect(executeErr).To(MatchError(jsonErr))
122122
})
123123
})
124124

@@ -149,7 +149,7 @@ var _ = Describe("install-plugin command", func() {
149149
})
150150

151151
It("returns the wrapped client(request/http status) error", func() {
152-
Expect(executeErr).To(MatchError(translatableerror.DownloadPluginHTTPError{Message: returnedErr.Status}))
152+
Expect(executeErr).To(MatchError(returnedErr))
153153
})
154154
})
155155
})
@@ -181,7 +181,7 @@ var _ = Describe("install-plugin command", func() {
181181
})
182182

183183
It("returns the NoCompatibleBinaryError", func() {
184-
Expect(executeErr).To(MatchError(translatableerror.NoCompatibleBinaryError{}))
184+
Expect(executeErr).To(MatchError(actionerror.NoCompatibleBinaryError{}))
185185
})
186186
})
187187

@@ -316,7 +316,7 @@ var _ = Describe("install-plugin command", func() {
316316
})
317317

318318
It("returns the error", func() {
319-
Expect(executeErr).To(MatchError(translatableerror.PluginInvalidError{}))
319+
Expect(executeErr).To(MatchError(actionerror.PluginInvalidError{}))
320320
Expect(testUI.Out).ToNot(Say("Installing plugin"))
321321

322322
Expect(fakeActor.GetAndValidatePluginCallCount()).To(Equal(1))
@@ -482,7 +482,7 @@ var _ = Describe("install-plugin command", func() {
482482
})
483483

484484
It("returns the error", func() {
485-
Expect(executeErr).To(MatchError(translatableerror.PluginInvalidError{}))
485+
Expect(executeErr).To(MatchError(actionerror.PluginInvalidError{}))
486486
Expect(testUI.Out).ToNot(Say("Installing plugin"))
487487
})
488488
})

command/plugin/add_plugin_repo_command.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (cmd AddPluginRepoCommand) Execute(args []string) error {
4747
"RepositoryURL": cmd.RequiredArgs.PluginRepoURL,
4848
})
4949
default:
50-
return shared.HandleError(err)
50+
return err
5151
}
5252

5353
return nil

command/plugin/add_plugin_repo_command_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"code.cloudfoundry.org/cli/command/commandfakes"
66
. "code.cloudfoundry.org/cli/command/plugin"
77
"code.cloudfoundry.org/cli/command/plugin/pluginfakes"
8-
"code.cloudfoundry.org/cli/command/translatableerror"
98
"code.cloudfoundry.org/cli/util/ui"
109
. "github.com/onsi/ginkgo"
1110
. "github.com/onsi/gomega"
@@ -40,7 +39,7 @@ var _ = Describe("add-plugin-repo command", func() {
4039
})
4140

4241
It("returns RepositoryNameTakenError", func() {
43-
Expect(executeErr).To(MatchError(translatableerror.RepositoryNameTakenError{Name: "some-repo"}))
42+
Expect(executeErr).To(MatchError(actionerror.RepositoryNameTakenError{Name: "some-repo"}))
4443
})
4544
})
4645

@@ -71,7 +70,7 @@ var _ = Describe("add-plugin-repo command", func() {
7170
})
7271

7372
It("handles the error", func() {
74-
Expect(executeErr).To(MatchError(translatableerror.AddPluginRepositoryError{Name: "some-repo", URL: "some-URL", Message: "404"}))
73+
Expect(executeErr).To(MatchError(actionerror.AddPluginRepositoryError{Name: "some-repo", URL: "some-URL", Message: "404"}))
7574
})
7675
})
7776

command/plugin/plugins_command.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (cmd PluginsCommand) displayOutdatedPlugins() error {
7575

7676
outdatedPlugins, err := cmd.Actor.GetOutdatedPlugins()
7777
if err != nil {
78-
return shared.HandleError(err)
78+
return err
7979
}
8080

8181
table := [][]string{{"plugin", "version", "latest version"}}

command/plugin/plugins_command_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ var _ = Describe("plugins Command", func() {
198198
})
199199
})
200200
It("displays the repository and the error", func() {
201-
Expect(executeErr).To(MatchError(translatableerror.GettingPluginRepositoryError{
201+
Expect(executeErr).To(MatchError(actionerror.GettingPluginRepositoryError{
202202
Name: "repo-1",
203203
Message: "404",
204204
}))

command/plugin/shared/handle_error.go

-43
This file was deleted.

0 commit comments

Comments
 (0)