Skip to content

Commit

Permalink
Fix first character or errors
Browse files Browse the repository at this point in the history
In some cases I've reworded errors so they do not begin with a proper
noun

Signed-off-by: Will Beason <willbeason@google.com>
  • Loading branch information
Will Beason committed Sep 28, 2021
1 parent f2d3026 commit 10ca257
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 55 deletions.
8 changes: 4 additions & 4 deletions constraint/pkg/client/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewBackend(opts ...BackendOpt) (*Backend, error) {
}

if b.driver == nil {
return nil, errors.New("No driver supplied to the backend")
return nil, errors.New("no driver supplied to the backend")
}

return b, nil
Expand All @@ -46,7 +46,7 @@ func NewBackend(opts ...BackendOpt) (*Backend, error) {
// NewClient creates a new client for the supplied backend.
func (b *Backend) NewClient(opts ...Opt) (*Client, error) {
if b.hasClient {
return nil, errors.New("Currently only one client per backend is supported")
return nil, errors.New("currently only one client per backend is supported")
}
var fields []string
for k := range validDataFields {
Expand All @@ -66,14 +66,14 @@ func (b *Backend) NewClient(opts ...Opt) (*Client, error) {
}
for _, field := range c.allowedDataFields {
if !validDataFields[field] {
return nil, fmt.Errorf("Invalid data field %s", field)
return nil, fmt.Errorf("invalid data field %s", field)
}
}
if len(errs) > 0 {
return nil, errs
}
if len(c.targets) == 0 {
return nil, errors.New("No targets registered. Please register a target via client.Targets()")
return nil, errors.New("no targets registered: please register a target via client.Targets()")
}
if err := b.driver.Init(context.Background()); err != nil {
return nil, err
Expand Down
24 changes: 12 additions & 12 deletions constraint/pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (a *rawCTArtifacts) Key() templateKey {
// complex tasks like rewriting Rego. Provides minimal validation.
func (c *Client) createRawTemplateArtifacts(templ *templates.ConstraintTemplate) (*rawCTArtifacts, error) {
if templ.ObjectMeta.Name == "" {
return nil, errors.New("Template has no name")
return nil, errors.New("invalid Template: missing name")
}
return &rawCTArtifacts{template: templ}, nil
}
Expand Down Expand Up @@ -305,7 +305,7 @@ func (c *Client) createTemplateArtifacts(templ *templates.ConstraintTemplate) (*
return nil, err
}
if entryPoint == nil {
return nil, fmt.Errorf("Failed to parse module for unknown reason")
return nil, fmt.Errorf("failed to parse module for unknown reason")
}

if err := rewriteModulePackage(artifacts.namePrefix, entryPoint); err != nil {
Expand All @@ -315,7 +315,7 @@ func (c *Client) createTemplateArtifacts(templ *templates.ConstraintTemplate) (*
req := map[string]struct{}{"violation": {}}

if err := requireRulesModule(entryPoint, req); err != nil {
return nil, fmt.Errorf("Invalid rego: %s", err)
return nil, fmt.Errorf("invalid rego: %s", err)
}

rr.AddEntryPointModule(artifacts.namePrefix, entryPoint)
Expand Down Expand Up @@ -474,14 +474,14 @@ func (c *Client) getTemplateNoLock(ctx context.Context, artifacts keyableArtifac
// for each target: cluster.<group>.<kind>.<name>.
func createConstraintSubPath(constraint *unstructured.Unstructured) (string, error) {
if constraint.GetName() == "" {
return "", errors.New("Constraint has no name")
return "", errors.New("invalid Constraint: missing name")
}
gvk := constraint.GroupVersionKind()
if gvk.Group == "" {
return "", fmt.Errorf("Empty group for the constrant named %s", constraint.GetName())
return "", fmt.Errorf("empty group for the constrant named %s", constraint.GetName())
}
if gvk.Kind == "" {
return "", fmt.Errorf("Empty kind for the constraint named %s", constraint.GetName())
return "", fmt.Errorf("empty kind for the constraint named %s", constraint.GetName())
}
return path.Join(createConstraintGKSubPath(gvk.GroupKind()), constraint.GetName()), nil
}
Expand Down Expand Up @@ -515,10 +515,10 @@ func constraintPathMerge(target, subpath string) string {
func (c *Client) getTemplateEntry(constraint *unstructured.Unstructured, lock bool) (*templateEntry, error) {
kind := constraint.GetKind()
if kind == "" {
return nil, fmt.Errorf("Constraint %s has no kind", constraint.GetName())
return nil, fmt.Errorf("kind missing from Constraint %q", constraint.GetName())
}
if constraint.GroupVersionKind().Group != constraintGroup {
return nil, fmt.Errorf("Constraint %s has the wrong group", constraint.GetName())
return nil, fmt.Errorf("wrong API Group for Constraint %q", constraint.GetName())
}
if lock {
c.constraintsMux.RLock()
Expand Down Expand Up @@ -684,7 +684,7 @@ func (c *Client) init() error {

libTempl := t.Library()
if libTempl == nil {
return fmt.Errorf("Target %s has no Rego library template", t.GetName())
return fmt.Errorf("target %q has no Rego library template", t.GetName())
}
libBuf := &bytes.Buffer{}
if err := libTempl.Execute(libBuf, map[string]string{
Expand All @@ -705,18 +705,18 @@ func (c *Client) init() error {
return fmt.Errorf("failed to parse module: %w", err)
}
if err := requireRulesModule(libModule, req); err != nil {
return fmt.Errorf("Problem with the below Rego for %s target:\n\n====%s\n====\n%s", t.GetName(), lib, err)
return fmt.Errorf("problem with the below Rego for %q target:\n\n====%s\n====\n%s", t.GetName(), lib, err)
}
err = rewriteModulePackage(modulePath, libModule)
if err != nil {
return err
}
src, err := format.Ast(libModule)
if err != nil {
return fmt.Errorf("Could not re-format Rego source: %v", err)
return fmt.Errorf("could not re-format Rego source: %v", err)
}
if err := c.backend.driver.PutModule(context.Background(), modulePath, string(src)); err != nil {
return fmt.Errorf("Error %s from compiled source:\n%s", err, src)
return fmt.Errorf("error %s from compiled source:\n%s", err, src)
}
}

Expand Down
2 changes: 1 addition & 1 deletion constraint/pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (h *badHandler) MatchSchema() apiextensions.JSONSchemaProps {

func (h *badHandler) ProcessData(obj interface{}) (bool, string, interface{}, error) {
if h.Errors {
return false, "", nil, errors.New("TEST ERROR")
return false, "", nil, errors.New("some error")
}
if !h.HandlesData {
return false, "", nil, nil
Expand Down
8 changes: 4 additions & 4 deletions constraint/pkg/client/crd_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,16 @@ func (h *crdHelper) validateCR(cr *unstructured.Unstructured, crd *apiextensions
return err.ToAggregate()
}
if errs := apivalidation.IsDNS1123Subdomain(cr.GetName()); len(errs) != 0 {
return fmt.Errorf("Invalid Name: %s", strings.Join(errs, "\n"))
return fmt.Errorf("invalid Name: %s", strings.Join(errs, "\n"))
}
if cr.GetKind() != crd.Spec.Names.Kind {
return fmt.Errorf("Wrong kind for constraint %s. Have %s, want %s", cr.GetName(), cr.GetKind(), crd.Spec.Names.Kind)
return fmt.Errorf("wrong kind for constraint %s. Have %s, want %s", cr.GetName(), cr.GetKind(), crd.Spec.Names.Kind)
}
if cr.GroupVersionKind().Group != constraintGroup {
return fmt.Errorf("Wrong group for constraint %s. Have %s, want %s", cr.GetName(), cr.GroupVersionKind().Group, constraintGroup)
return fmt.Errorf("wrong group for constraint %s. Have %s, want %s", cr.GetName(), cr.GroupVersionKind().Group, constraintGroup)
}
if !supportedVersions[cr.GroupVersionKind().Version] {
return fmt.Errorf("Wrong version for constraint %s. Have %s, supported: %v", cr.GetName(), cr.GroupVersionKind().Version, supportedVersions)
return fmt.Errorf("wrong version for constraint %s. Have %s, supported: %v", cr.GetName(), cr.GroupVersionKind().Version, supportedVersions)
}
return nil
}
14 changes: 7 additions & 7 deletions constraint/pkg/client/drivers/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,20 @@ func copyModules(modules map[string]*ast.Module, filter string) map[string]*ast.

func (d *driver) checkModuleName(name string) error {
if name == "" {
return fmt.Errorf("Module name cannot be empty")
return fmt.Errorf("module name cannot be empty")
}
if strings.HasPrefix(name, moduleSetPrefix) {
return fmt.Errorf("Single modules not allowed to use name prefix %s", moduleSetPrefix)
return fmt.Errorf("single modules not allowed to use name prefix %q", moduleSetPrefix)
}
return nil
}

func (d *driver) checkModuleSetName(name string) error {
if name == "" {
return fmt.Errorf("Modules name prefix cannot be empty")
return fmt.Errorf("modules name prefix cannot be empty")
}
if strings.Contains(name, moduleSetSep) {
return fmt.Errorf("Modules name prefix not allowed to contain the sequence n%s", moduleSetSep)
return fmt.Errorf("modules name prefix not allowed to contain the sequence n%s", moduleSetSep)
}
return nil
}
Expand Down Expand Up @@ -259,7 +259,7 @@ func (d *driver) listModuleSet(namePrefix string) []string {
func parsePath(path string) ([]string, error) {
p, ok := storage.ParsePathEscaped(path)
if !ok {
return nil, fmt.Errorf("Bad data path: %s", path)
return nil, fmt.Errorf("bad data path: %q", path)
}
return p, nil
}
Expand Down Expand Up @@ -397,11 +397,11 @@ func (d *driver) Dump(ctx context.Context) (string, error) {
var dt interface{}
// There should be only 1 or 0 expression values
if len(data) > 1 {
return "", errors.New("Too many dump results")
return "", errors.New("too many dump results")
}
for _, da := range data {
if len(data) > 1 {
return "", errors.New("Too many expressions results")
return "", errors.New("too many expressions results")
}
for _, e := range da.Expressions {
dt = e.Value
Expand Down
6 changes: 3 additions & 3 deletions constraint/pkg/client/drivers/remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func New(args ...Arg) (drivers.Driver, error) {
arg(i)
}
if i.url == "" {
return nil, errors.New("OPA URL not set")
return nil, errors.New("missing URL for OPA")
}
return &driver{opa: newHTTPClient(i.url, i.opaCAs, i.auth), traceEnabled: i.traceEnabled}, nil
}
Expand Down Expand Up @@ -140,15 +140,15 @@ func makeURLPath(path string) (string, error) {
builder.Reset()
continue
} else {
return "", fmt.Errorf("Mismatched bracketing: %s", path)
return "", fmt.Errorf("mismatched bracketing: %q", path)
}
}
if ch == "]" {
if openBracket {
openBracket = false
continue
} else {
return "", fmt.Errorf("Mismatched bracketing: %s", path)
return "", fmt.Errorf("mismatched bracketing: %q", path)
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions constraint/pkg/client/drivers/remote/remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,35 @@ type testClient struct {
}

func (c *testClient) InsertPolicy(id string, bs []byte) error {
return errors.New("NOT IMPLEMENTED")
return errors.New("not implemented")
}

func (c *testClient) DeletePolicy(id string) error {
return errors.New("NOT IMPLEMENTED")
return errors.New("not implemented")
}

func (c *testClient) ListPolicies() (*QueryResult, error) {
return nil, errors.New("NOT IMPLEMENTED")
return nil, errors.New("not implemented")
}

func (c *testClient) Prefix(path string) Data {
return c
}

func (c *testClient) PatchData(path string, op string, value *interface{}) error {
return errors.New("NOT IMPLEMENTED")
return errors.New("not implemented")
}

func (c *testClient) PutData(path string, value interface{}) error {
return errors.New("NOT IMPLEMENTED")
return errors.New("not implemented")
}

func (c *testClient) PostData(path string, value interface{}) (json.RawMessage, error) {
return nil, errors.New("NOT IMPLEMENTED")
return nil, errors.New("not implemented")
}

func (c *testClient) DeleteData(path string) error {
return errors.New("NOT IMPLEMENTED")
return errors.New("not implemented")
}

func (c *testClient) Query(path string, value interface{}) (*QueryResult, error) {
Expand Down
Loading

0 comments on commit 10ca257

Please sign in to comment.