Skip to content

Commit

Permalink
use fmt.Errorf to return errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianczech committed Mar 14, 2024
1 parent f0e47db commit a0edfa2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
15 changes: 7 additions & 8 deletions pkg/properties/normalized.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package properties

import (
"errors"
"fmt"
"github.com/paloaltonetworks/pan-os-codegen/pkg/content"
"github.com/paloaltonetworks/pan-os-codegen/pkg/naming"
Expand Down Expand Up @@ -263,13 +262,13 @@ func (spec *Normalization) AddDefaultTypesForParams() error {
// Sanity basic checks for specification (normalization) e.g. check if at least 1 location is defined.
func (spec *Normalization) Sanity() error {
if spec.Name == "" {
return errors.New("name is required")
return fmt.Errorf("name is required")
}
if spec.Locations == nil {
return errors.New("at least 1 location is required")
return fmt.Errorf("at least 1 location is required")
}
if spec.GoSdkPath == nil {
return errors.New("golang SDK path is required")
return fmt.Errorf("golang SDK path is required")
}

return nil
Expand All @@ -280,18 +279,18 @@ func (spec *Normalization) Validate() []error {
var checks []error

if strings.Contains(spec.TerraformProviderSuffix, "panos_") {
checks = append(checks, errors.New("suffix for Terraform provider cannot contain `panos_`"))
checks = append(checks, fmt.Errorf("suffix for Terraform provider cannot contain `panos_`"))
}
for _, suffix := range spec.XpathSuffix {
if strings.Contains(suffix, "/") {
checks = append(checks, errors.New("XPath cannot contain /"))
checks = append(checks, fmt.Errorf("XPath cannot contain /"))
}
}
if len(spec.Locations) < 1 {
checks = append(checks, errors.New("at least 1 location is required"))
checks = append(checks, fmt.Errorf("at least 1 location is required"))
}
if len(spec.GoSdkPath) < 2 {
checks = append(checks, errors.New("golang SDK path should contain at least 2 elements of the path"))
checks = append(checks, fmt.Errorf("golang SDK path should contain at least 2 elements of the path"))
}

return checks
Expand Down
3 changes: 1 addition & 2 deletions pkg/translate/funcs.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package translate

import (
"errors"
"fmt"
"github.com/paloaltonetworks/pan-os-codegen/pkg/naming"
"github.com/paloaltonetworks/pan-os-codegen/pkg/properties"
Expand All @@ -11,7 +10,7 @@ import (
// AsEntryXpath functions used in location.tmpl to generate XPath for location.
func AsEntryXpath(location, xpath string) (string, error) {
if !strings.Contains(xpath, "$") || !strings.Contains(xpath, "}") {
return "", errors.New("$ followed by } should exists in xpath'")
return "", fmt.Errorf("xpath '%s' is missing '$' followed by '}'", xpath)
}
asEntryXpath := generateXpathForLocation(location, xpath)
return asEntryXpath, nil
Expand Down

0 comments on commit a0edfa2

Please sign in to comment.