1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00

Merge pull request #935 from NoSkillGirl/feature/cli_error_messages

updated sanitized error
This commit is contained in:
Jim Bugwadia 2020-06-20 23:30:20 -07:00 committed by GitHub
commit 7cb49b6b34
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 8 deletions

View file

@ -58,7 +58,7 @@ func Command() *cobra.Command {
}()
if len(resourcePaths) == 0 && !cluster {
return sanitizedError.New(fmt.Sprintf("Specify path to resource file or cluster name"))
return sanitizedError.NewWithError(fmt.Sprintf("resource file or cluster required"), err)
}
policies, openAPIController, err := common.GetPoliciesValidation(policyPaths)
@ -73,7 +73,7 @@ func Command() *cobra.Command {
os.Exit(3)
}
if policyHasVariables(*policy) {
return sanitizedError.New(fmt.Sprintf("Policy %v is not valid - 'apply' does not support policies with variables", policy.Name))
return sanitizedError.NewWithError(fmt.Sprintf("invalid policy %s. 'apply' does not support policies with variables", policy.Name), err)
}
}
@ -91,7 +91,7 @@ func Command() *cobra.Command {
resources, err := getResources(policies, resourcePaths, dClient)
if err != nil {
return sanitizedError.NewWithError("Failed to load resources", err)
return sanitizedError.NewWithError("failed to load resources", err)
}
for i, policy := range policies {
@ -102,7 +102,7 @@ func Command() *cobra.Command {
err = applyPolicyOnResource(policy, resource)
if err != nil {
return sanitizedError.New(fmt.Errorf("Issues applying policy %v on resource %v", policy.Name, resource.GetName()).Error())
return sanitizedError.NewWithError(fmt.Errorf("failed to apply policy %v on resource %v", policy.Name, resource.GetName()).Error(), err)
}
}
}
@ -310,7 +310,7 @@ func applyPolicyOnResource(policy *v1.ClusterPolicy, resource *unstructured.Unst
}
}
if responseError == true{
if responseError == true {
os.Exit(1)
}
return nil

View file

@ -32,7 +32,7 @@ func GetPolicies(paths []string) (policies []*v1.ClusterPolicy, error error) {
if fileDesc.IsDir() {
files, err := ioutil.ReadDir(path)
if err != nil {
return nil, sanitizedError.New(fmt.Sprintf("failed to parse %v", path))
return nil, sanitizedError.NewWithError(fmt.Sprintf("failed to parse %v", path), err)
}
listOfFiles := make([]string, 0)
@ -43,7 +43,7 @@ func GetPolicies(paths []string) (policies []*v1.ClusterPolicy, error error) {
policiesFromDir, err := GetPolicies(listOfFiles)
if err != nil {
log.Error(err, fmt.Sprintf("failed to extract policies from %v", listOfFiles))
return nil, sanitizedError.New(("failed to extract policies"))
return nil, sanitizedError.NewWithError(("failed to extract policies"), err)
}
policies = append(policies, policiesFromDir...)
@ -134,7 +134,7 @@ func GetPoliciesValidation(policyPaths []string) ([]*v1.ClusterPolicy, *openapi.
policies, err := GetPolicies(policyPaths)
if err != nil {
if !sanitizedError.IsErrorSanitized(err) {
return nil, nil, sanitizedError.New((fmt.Sprintf("failed to parse %v path/s.", policyPaths)))
return nil, nil, sanitizedError.NewWithError((fmt.Sprintf("failed to parse %v path/s.", policyPaths)), err)
}
return nil, nil, err
}