Skip to content

Commit

Permalink
Improve error messages for odo delete and odo project delete (#5149)
Browse files Browse the repository at this point in the history
* Improve error message for deleting project.

* Improve error message for `ode delete` when user is not logged in.

* Apply code review suggestions regarding handling error messages.

* Add missing else statement.

* Fix linter once again.
  • Loading branch information
Berreek authored Oct 25, 2021
1 parent a9998bf commit 3edb168
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/odo/cli/project/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (pdo *ProjectDeleteOptions) Validate() (err error) {
// Validate existence of the project to be deleted
isValidProject, err := project.Exists(pdo.Context, pdo.projectName)
if !isValidProject {
return fmt.Errorf("The project %s does not exist. Please check the list of projects using `odo project list`", pdo.projectName)
return fmt.Errorf("The project %q does not exist. Please check the list of projects using `odo project list`", pdo.projectName)
}
return
}
Expand Down
9 changes: 8 additions & 1 deletion pkg/odo/genericclioptions/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package genericclioptions
import (
"context"
"fmt"
kerrors "k8s.io/apimachinery/pkg/api/errors"

"github.com/openshift/odo/pkg/localConfigProvider"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -49,7 +50,13 @@ func (o *internalCxt) resolveNamespace(configProvider localConfigProvider.LocalC
// check that the specified namespace exists
_, err := o.KClient.GetClient().CoreV1().Namespaces().Get(context.TODO(), namespace, metav1.GetOptions{})
if err != nil {
errFormat := fmt.Sprintf("You don't have permission to create or set namespace '%s' or the namespace doesn't exist. Please create or set a different namespace\n\t", namespace)
var errFormat string
if kerrors.IsForbidden(err) {
errFormat = "You are currently not logged in into the cluster. Use `odo login` first to perform any operation on cluster"
} else {
errFormat = fmt.Sprintf("You don't have permission to create or set namespace %q or the namespace doesn't exist. Please create or set a different namespace\n\t", namespace)
}

// errFormat := fmt.Sprint(e1, "%s project create|set <project_name>")
err = checkProjectCreateOrDeleteOnlyOnInvalidNamespaceNoFmt(command, errFormat)
if err != nil {
Expand Down

0 comments on commit 3edb168

Please sign in to comment.