Skip to content

Commit

Permalink
Improve cx status error message if resource not found
Browse files Browse the repository at this point in the history
  • Loading branch information
deliahu committed Feb 12, 2019
1 parent 4197d8d commit d93b9b5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cli/cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ func runGet(cmd *cobra.Command, args []string) (string, error) {
}

if _, err = resourcesRes.Context.VisibleResourceByName(resourceNameOrType); err != nil {
if rerr, ok := err.(resource.ResourceError); ok && rerr.Kind == resource.ErrNotFound {
return "", errors.New(s.ErrUndefinedNameOrType(resourceNameOrType))
if rerr, ok := err.(resource.ResourceError); ok && rerr.Kind == resource.ErrNameNotFound {
return "", resource.ErrorNameOrTypeNotFound(resourceNameOrType)
}
return "", err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func (ctx *Context) VisibleResourcesByName(name string) []ComputedResource {
func (ctx *Context) VisibleResourceByName(name string) (ComputedResource, error) {
resources := ctx.VisibleResourcesByName(name)
if len(resources) == 0 {
return nil, resource.ErrorNotFound(name, resource.UnknownType)
return nil, resource.ErrorNameNotFound(name)
}
if len(resources) > 1 {
validStrs := make([]string, len(resources))
Expand Down
18 changes: 18 additions & 0 deletions pkg/api/resource/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const (
ErrUnknown ErrorKind = iota
ErrUnknownKind
ErrNotFound
ErrNameNotFound
ErrNameOrTypeNotFound
ErrInvalidType
)

Expand All @@ -36,6 +38,8 @@ var (
"err_unknown",
"err_unknown_kind",
"err_not_found",
"err_name_not_found",
"err_name_or_type_not_found",
"err_invalid_type",
}
)
Expand Down Expand Up @@ -87,6 +91,20 @@ func ErrorNotFound(name string, resourceType Type) error {
}
}

func ErrorNameNotFound(name string) error {
return ResourceError{
Kind: ErrNameNotFound,
message: fmt.Sprintf("resource name %s not found", s.UserStr(name)),
}
}

func ErrorNameOrTypeNotFound(nameOrType string) error {
return ResourceError{
Kind: ErrNameOrTypeNotFound,
message: fmt.Sprintf("resource name or type %s not found", s.UserStr(nameOrType)),
}
}

func ErrorInvalidType(invalid string) error {
return ResourceError{
Kind: ErrInvalidType,
Expand Down

0 comments on commit d93b9b5

Please sign in to comment.