Skip to content

Commit

Permalink
changed errors
Browse files Browse the repository at this point in the history
Signed-off-by: ashish <[email protected]>
  • Loading branch information
Revolyssup committed Aug 25, 2021
1 parent 123bac5 commit 0ac974c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
8 changes: 1 addition & 7 deletions utils/manifests/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ const (
ErrGetSchemasCode = "1002"
ErrGetAPIVersionCode = "1003"
ErrGetAPIGroupCode = "1004"
ErrParsingJsonCode = "1005"
ErrPopulatingYamlCode = "1006"
ErrPopulatingYamlCode = "1005"
)

func ErrGetCrdNames(err error) error {
Expand All @@ -25,11 +24,6 @@ func ErrGetAPIGroup(err error) error {
return errors.New(ErrGetAPIGroupCode, errors.Alert, []string{"Error getting api group"}, []string{err.Error()}, []string{"Api group could not be parsed"}, []string{"Make sure the filter passed is correct"})
}

func ErrParsingJson(err error) error {
return errors.New(ErrParsingJsonCode, errors.Alert, []string{"Error parsing json"}, []string{err.Error()}, []string{"Json could not be parsed"}, []string{"Make sure the path passed in filter is correct"})

}
func ErrPopulatingYaml(err error) error {
return errors.New(ErrPopulatingYamlCode, errors.Alert, []string{"Error populating yaml"}, []string{err.Error()}, []string{"Yaml could not be populated with the returned manifests"}, []string{""})

}
19 changes: 14 additions & 5 deletions utils/manifests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ func getDefinitions(crd string, resource int, cfg Config, filepath string, binPa
definitionRef := strings.ToLower(crd) + ".meshery.layer5.io"
apiVersion, err := getApiVersion(binPath, filepath, crd)
if err != nil {
return "", err
return "", ErrGetAPIVersion(err)
}
apiGroup, err := getApiGrp(binPath, filepath, crd)
if err != nil {
return "", err
return "", ErrGetAPIGroup(err)
}
//getting defintions for different native resources
def.Spec.DefinitionRef.Name = definitionRef
Expand Down Expand Up @@ -78,6 +78,9 @@ func getSchema(crd string, filepath string, binPath string, cfg Config) (string,
if err := json.Unmarshal(out.Bytes(), &schema); err != nil {
return "", err
}
if len(schema) == 0 || len(schema[0]) == 0 {
return "", err
}
(schema)[0][0]["title"] = crdname
var output []byte
output, err = json.MarshalIndent(schema[0][0], "", " ")
Expand Down Expand Up @@ -142,12 +145,15 @@ func getApiVersion(binPath string, filepath string, crd string) (string, error)
schemaCmd.Stderr = &er
err := schemaCmd.Run()
if err != nil {
return er.String(), ErrGetAPIVersion(err)
return er.String(), err
}
grp := [][]map[string]interface{}{}
if err := json.Unmarshal(out.Bytes(), &grp); err != nil {
return "", err
}
if len(grp) == 0 || len(grp[0]) == 0 {
return "", err
}
var output []byte
output, err = json.Marshal(grp[0][0]["name"])
if err != nil {
Expand All @@ -170,13 +176,16 @@ func getApiGrp(binPath string, filepath string, crd string) (string, error) {
schemaCmd.Stderr = &er
err := schemaCmd.Run()
if err != nil {
return er.String(), ErrGetAPIGroup(err)
return er.String(), err
}
v := [][]map[string]interface{}{}
if err := json.Unmarshal(out.Bytes(), &v); err != nil {
return "", err
}
var output []byte
if len(v) == 0 || len(v[0]) == 0 {
return "", err
}
output, err = json.Marshal(v[0][0]["group"])
if err != nil {
return "", err
Expand All @@ -200,7 +209,7 @@ func filterYaml(yamlPath string, filter []string, binPath string) error {
cmd.Stderr = &er
err := cmd.Run()
if err != nil {
return ErrGetCrdNames(err)
return err
}
path := filepath.Join(os.TempDir(), "/test.yaml")
err = populateTempyaml(out.String(), path)
Expand Down

0 comments on commit 0ac974c

Please sign in to comment.