From a0edfa2039baa8c0bc8d8f725619b3f5f00cac5d Mon Sep 17 00:00:00 2001 From: Sebastian Czech Date: Thu, 14 Mar 2024 13:32:25 +0100 Subject: [PATCH] use fmt.Errorf to return errors --- pkg/properties/normalized.go | 15 +++++++-------- pkg/translate/funcs.go | 3 +-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/pkg/properties/normalized.go b/pkg/properties/normalized.go index 8d599391..a665b277 100644 --- a/pkg/properties/normalized.go +++ b/pkg/properties/normalized.go @@ -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" @@ -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 @@ -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 diff --git a/pkg/translate/funcs.go b/pkg/translate/funcs.go index 7c7d8b83..1328d8fe 100644 --- a/pkg/translate/funcs.go +++ b/pkg/translate/funcs.go @@ -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" @@ -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