Skip to content

Commit

Permalink
fix: Classify not found policies and improve errors (#697)
Browse files Browse the repository at this point in the history
  • Loading branch information
erezrokah committed May 11, 2022
1 parent 7d7077e commit 413a2cf
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/ui/console/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/cloudquery/cloudquery/internal/getter"
"github.com/cloudquery/cloudquery/pkg/policy"
"github.com/cloudquery/cloudquery/pkg/ui"
"github.com/cloudquery/cq-provider-sdk/provider/diag"

"github.com/fatih/color"
"github.com/olekukonko/tablewriter"
Expand Down Expand Up @@ -43,15 +44,22 @@ func FilterPolicies(policyPath string, policies policy.Policies) (policy.Policie
}
return policy.Policies{p}, nil
}
// run hub detector
// run hub detector. We got here if we couldn't find the policy specified by the command argument in the configuration
p, found, err := policy.DetectPolicy(policyName, subPath)
if err != nil {
return nil, err
}
if found {
return policy.Policies{p}, nil
}
return nil, fmt.Errorf("no policy with name %s found in configuration or remote. Available in config: %s", policyName, policies.All())

configPolicies := policies.All()
if len(configPolicies) == 0 {
return nil, diag.FromError(fmt.Errorf("no valid policy with name %q found. If using a local policy directory, ensure the path is correct and the directory exists", policyName), diag.USER)
}

return nil, diag.FromError(fmt.Errorf("no valid policy with name %q found in configuration or remote. Available in config: %s", policyName, configPolicies), diag.USER)

}

func buildDescribePolicyTable(t ui.Table, pp policy.Policies, policyRootPath string) {
Expand Down

0 comments on commit 413a2cf

Please sign in to comment.