Skip to content

Commit fb8841b

Browse files
committed
move push and plugin errors into actionerror
1 parent 13b6f47 commit fb8841b

Some content is hidden

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

49 files changed

+423
-365
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package actionerror
2+
3+
import "fmt"
4+
5+
type AddPluginRepositoryError struct {
6+
Name string
7+
URL string
8+
Message string
9+
}
10+
11+
func (e AddPluginRepositoryError) Error() string {
12+
return fmt.Sprintf("Could not add repository '%s' from %s: %s", e.Name, e.URL, e.Message)
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package actionerror
2+
3+
import "fmt"
4+
5+
type AppNotFoundInManifestError struct {
6+
Name string
7+
}
8+
9+
func (e AppNotFoundInManifestError) Error() string {
10+
return fmt.Sprintf("specfied app: %s not found in manifest", e.Name)
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package actionerror
2+
3+
type CommandLineOptionsWithMultipleAppsError struct{}
4+
5+
func (CommandLineOptionsWithMultipleAppsError) Error() string {
6+
return "cannot use command line flag with multiple apps"
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package actionerror
2+
3+
import "fmt"
4+
5+
// NoDomainsFoundError is returned when there are no private or shared domains
6+
// accessible to an organization.
7+
type NoDomainsFoundError struct {
8+
OrganizationGUID string
9+
}
10+
11+
func (e NoDomainsFoundError) Error() string {
12+
return fmt.Sprintf("No private or shared domains found for organization (GUID: %s)", e.OrganizationGUID)
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package actionerror
2+
3+
import "fmt"
4+
5+
// FetchingPluginInfoFromRepositoryError is returned an error is encountered
6+
// getting plugin info from a repository.
7+
type FetchingPluginInfoFromRepositoryError struct {
8+
RepositoryName string
9+
Err error
10+
}
11+
12+
func (e FetchingPluginInfoFromRepositoryError) Error() string {
13+
return fmt.Sprintf("Plugin repository %s returned %s.", e.RepositoryName, e.Err.Error())
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package actionerror
2+
3+
import "fmt"
4+
5+
// GettingPluginRepositoryError is returned when there's an error
6+
// accessing the plugin repository.
7+
type GettingPluginRepositoryError struct {
8+
Name string
9+
Message string
10+
}
11+
12+
func (e GettingPluginRepositoryError) Error() string {
13+
return fmt.Sprintf("Could not get plugin repository '%s'\n%s", e.Name, e.Message)
14+
}
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package actionerror
2+
3+
type MissingNameError struct{}
4+
5+
func (MissingNameError) Error() string {
6+
return "name not specified for app"
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package actionerror
2+
3+
// NoCompatibleBinaryError is returned when a repository contains a specified
4+
// plugin but not for the specified platform.
5+
type NoCompatibleBinaryError struct {
6+
}
7+
8+
func (e NoCompatibleBinaryError) Error() string {
9+
return "Plugin requested has no binary available for your platform."
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package actionerror
2+
3+
import "fmt"
4+
5+
type NonexistentAppPathError struct {
6+
Path string
7+
}
8+
9+
func (e NonexistentAppPathError) Error() string {
10+
return fmt.Sprint("app path not found:", e.Path)
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package actionerror
2+
3+
// PluginBinaryRemoveFailedError is returned when running the plugin binary fails.
4+
type PluginBinaryRemoveFailedError struct {
5+
Err error
6+
}
7+
8+
func (e PluginBinaryRemoveFailedError) Error() string {
9+
return e.Err.Error()
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package actionerror
2+
3+
// PluginCommandsConflictError is returned when a plugin command name conflicts
4+
// with a core or existing plugin command name.
5+
type PluginCommandsConflictError struct {
6+
PluginName string
7+
PluginVersion string
8+
CommandNames []string
9+
CommandAliases []string
10+
}
11+
12+
func (PluginCommandsConflictError) Error() string {
13+
return ""
14+
}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package actionerror
2+
3+
// PluginExecuteError is returned when running the plugin binary fails.
4+
type PluginExecuteError struct {
5+
Err error
6+
}
7+
8+
func (e PluginExecuteError) Error() string {
9+
return e.Err.Error()
10+
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package actionerror
2+
3+
// PluginInvalidError is returned with a plugin is invalid because it is
4+
// missing a name or has 0 commands.
5+
type PluginInvalidError struct {
6+
Err error
7+
}
8+
9+
func (PluginInvalidError) Error() string {
10+
return "File is not a valid cf CLI plugin binary."
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package actionerror
2+
3+
import "fmt"
4+
5+
// PluginNotFoundError is an error returned when a plugin is not found.
6+
type PluginNotFoundError struct {
7+
PluginName string
8+
}
9+
10+
// Error outputs a plugin not found error message.
11+
func (e PluginNotFoundError) Error() string {
12+
return fmt.Sprintf("Plugin name %s does not exist.", e.PluginName)
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package actionerror
2+
3+
import "fmt"
4+
5+
// PluginNotFoundInAnyRepositoryError is an error returned when a plugin cannot
6+
// be found in any repositories.
7+
type PluginNotFoundInAnyRepositoryError struct {
8+
PluginName string
9+
}
10+
11+
// Error outputs that the plugin cannot be found in any repositories.
12+
func (e PluginNotFoundInAnyRepositoryError) Error() string {
13+
return fmt.Sprintf("Plugin %s not found in any registered repo", e.PluginName)
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package actionerror
2+
3+
import "fmt"
4+
5+
// PluginNotFoundInRepositoryError is an error returned when a plugin is not
6+
// found.
7+
type PluginNotFoundInRepositoryError struct {
8+
PluginName string
9+
RepositoryName string
10+
}
11+
12+
// Error outputs the plugin not found in repository error message.
13+
func (e PluginNotFoundInRepositoryError) Error() string {
14+
return fmt.Sprintf("Plugin %s not found in repository %s", e.PluginName, e.RepositoryName)
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package actionerror
2+
3+
import "fmt"
4+
5+
type RepositoryAlreadyExistsError struct {
6+
Name string
7+
URL string
8+
}
9+
10+
func (e RepositoryAlreadyExistsError) Error() string {
11+
return fmt.Sprintf("%s already registered as %s.", e.URL, e.Name)
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package actionerror
2+
3+
import "fmt"
4+
5+
type RepositoryNameTakenError struct {
6+
Name string
7+
}
8+
9+
func (e RepositoryNameTakenError) Error() string {
10+
return fmt.Sprintf("Plugin repo named '%s' already exists, please use another name.", e.Name)
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package actionerror
2+
3+
import "fmt"
4+
5+
type RepositoryNotRegisteredError struct {
6+
Name string
7+
}
8+
9+
func (e RepositoryNotRegisteredError) Error() string {
10+
return fmt.Sprintf("Plugin repository %s not found", e.Name)
11+
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package actionerror
2+
3+
type UploadFailedError struct {
4+
Err error
5+
}
6+
7+
func (UploadFailedError) Error() string {
8+
return "upload failed"
9+
}

actor/pluginaction/install.go

+5-27
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"sort"
88
"strings"
99

10+
"code.cloudfoundry.org/cli/actor/actionerror"
1011
"code.cloudfoundry.org/cli/api/plugin"
1112
"code.cloudfoundry.org/cli/util/configv3"
1213
"code.cloudfoundry.org/cli/util/generic"
@@ -26,29 +27,6 @@ type CommandList interface {
2627
HasAlias(string) bool
2728
}
2829

29-
// PluginInvalidError is returned with a plugin is invalid because it is
30-
// missing a name or has 0 commands.
31-
type PluginInvalidError struct {
32-
Err error
33-
}
34-
35-
func (PluginInvalidError) Error() string {
36-
return "File is not a valid cf CLI plugin binary."
37-
}
38-
39-
// PluginCommandConflictError is returned when a plugin command name conflicts
40-
// with a core or existing plugin command name.
41-
type PluginCommandsConflictError struct {
42-
PluginName string
43-
PluginVersion string
44-
CommandAliases []string
45-
CommandNames []string
46-
}
47-
48-
func (PluginCommandsConflictError) Error() string {
49-
return ""
50-
}
51-
5230
// CreateExecutableCopy makes a temporary copy of a plugin binary and makes it
5331
// executable.
5432
//
@@ -80,8 +58,8 @@ func (actor Actor) CreateExecutableCopy(path string, tempPluginDir string) (stri
8058
return executablePath, nil
8159
}
8260

83-
// DownloadBinaryFromURL fetches a plugin binary from the specified URL, if
84-
// it exists.
61+
// DownloadExecutableBinaryFromURL fetches a plugin binary from the specified
62+
// URL, if it exists.
8563
func (actor Actor) DownloadExecutableBinaryFromURL(pluginURL string, tempPluginDir string, proxyReader plugin.ProxyReader) (string, error) {
8664
tempFile, err := makeTempFile(tempPluginDir)
8765
if err != nil {
@@ -106,7 +84,7 @@ func (actor Actor) FileExists(path string) bool {
10684
func (actor Actor) GetAndValidatePlugin(pluginMetadata PluginMetadata, commandList CommandList, path string) (configv3.Plugin, error) {
10785
plugin, err := pluginMetadata.GetMetadata(path)
10886
if err != nil || plugin.Name == "" || len(plugin.Commands) == 0 {
109-
return configv3.Plugin{}, PluginInvalidError{Err: err}
87+
return configv3.Plugin{}, actionerror.PluginInvalidError{Err: err}
11088
}
11189

11290
installedPlugins := actor.config.Plugins()
@@ -152,7 +130,7 @@ func (actor Actor) GetAndValidatePlugin(pluginMetadata PluginMetadata, commandLi
152130
return strings.ToLower(conflictingAliases[i]) < strings.ToLower(conflictingAliases[j])
153131
})
154132

155-
return configv3.Plugin{}, PluginCommandsConflictError{
133+
return configv3.Plugin{}, actionerror.PluginCommandsConflictError{
156134
PluginName: plugin.Name,
157135
PluginVersion: plugin.Version.String(),
158136
CommandNames: conflictingNames,

0 commit comments

Comments
 (0)