Skip to content

Commit

Permalink
chore: improve error logs (#20050)
Browse files Browse the repository at this point in the history
Signed-off-by: ajinkyak423 <[email protected]>
  • Loading branch information
ajinkyak423 authored Sep 22, 2024
1 parent 5f23bb6 commit 0573ed7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
14 changes: 7 additions & 7 deletions hack/gen-catalog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func generateCommandsDocs(out io.Writer) error {
for _, c := range toolSubCommand.Commands() {
var cmdDesc bytes.Buffer
if err := doc.GenMarkdown(c, &cmdDesc); err != nil {
return err
return fmt.Errorf("error generating Markdown for command: %v : %w", c, err)
}
for _, line := range strings.Split(cmdDesc.String(), "\n") {
if strings.HasPrefix(line, "### SEE ALSO") {
Expand All @@ -194,19 +194,19 @@ func buildConfigFromFS(templatesDir string, triggersDir string) (map[string]serv
templatesCfg := map[string]services.Notification{}
err := filepath.Walk(templatesDir, func(p string, info os.FileInfo, e error) error {
if e != nil {
return e
return fmt.Errorf("error navigating the templates dirctory: %s : %w", templatesDir, e)
}
if info.IsDir() {
return nil
}
data, err := os.ReadFile(p)
if err != nil {
return err
return fmt.Errorf("error reading the template file: %s : %w", p, err)
}
name := strings.Split(path.Base(p), ".")[0]
var template services.Notification
if err := yaml.Unmarshal(data, &template); err != nil {
return err
return fmt.Errorf("error unmarshaling the data from file: %s : %w", p, err)
}
templatesCfg[name] = template
return nil
Expand All @@ -218,19 +218,19 @@ func buildConfigFromFS(templatesDir string, triggersDir string) (map[string]serv
triggersCfg := map[string][]triggers.Condition{}
err = filepath.Walk(triggersDir, func(p string, info os.FileInfo, e error) error {
if e != nil {
return e
return fmt.Errorf("error navigating the triggers dirctory: %s : %w", triggersDir, e)
}
if info.IsDir() {
return nil
}
data, err := os.ReadFile(p)
if err != nil {
return err
return fmt.Errorf("error reading the trigger file: %s : %w", p, err)
}
name := strings.Split(path.Base(p), ".")[0]
var trigger []triggers.Condition
if err := yaml.Unmarshal(data, &trigger); err != nil {
return err
return fmt.Errorf("error unmarshaling the data from file: %s : %w", p, err)
}
triggersCfg[name] = trigger
return nil
Expand Down
8 changes: 4 additions & 4 deletions hack/gen-docs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func updateMkDocsNav(parent string, child string, subchild string, files []strin
sort.Strings(files)
data, err := os.ReadFile("mkdocs.yml")
if err != nil {
return err
return fmt.Errorf("error reading mkdocs.yml: %w", err)
}
var un unstructured.Unstructured
if e := yaml.Unmarshal(data, &un.Object); e != nil {
Expand All @@ -46,12 +46,12 @@ func updateMkDocsNav(parent string, child string, subchild string, files []strin
nav := un.Object["nav"].([]interface{})
rootitem, _ := findNavItem(nav, parent)
if rootitem == nil {
return fmt.Errorf("Can't find '%s' root item in mkdoc.yml", parent)
return fmt.Errorf("can't find '%s' root item in mkdoc.yml", parent)
}
rootnavitemmap := rootitem.(map[interface{}]interface{})
childnav, _ := findNavItem(rootnavitemmap[parent].([]interface{}), child)
if childnav == nil {
return fmt.Errorf("Can't find '%s' chile item under '%s' parent item in mkdoc.yml", child, parent)
return fmt.Errorf("can't find '%s' chile item under '%s' parent item in mkdoc.yml", child, parent)
}

childnavmap := childnav.(map[interface{}]interface{})
Expand All @@ -63,7 +63,7 @@ func updateMkDocsNav(parent string, child string, subchild string, files []strin
childnavmap[child] = append(childnavitems, commands)
newmkdocs, err := yaml.Marshal(un.Object)
if err != nil {
return err
return fmt.Errorf("error in marshaling final configmap: %w", err)
}

// The marshaller drops custom tags, so re-add this one. Turns out this is much less invasive than trying to handle
Expand Down
3 changes: 2 additions & 1 deletion hack/gen-resources/util/gen_options_parser.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package util

import (
"fmt"
"os"

"gopkg.in/yaml.v2"
Expand Down Expand Up @@ -55,7 +56,7 @@ func setDefaults(opts *GenerateOpts) {
func Parse(opts *GenerateOpts, file string) error {
fp, err := os.ReadFile(file)
if err != nil {
return err
return fmt.Errorf("error reading the template file: %s : %w", file, err)
}

if e := yaml.Unmarshal(fp, &opts); e != nil {
Expand Down
4 changes: 2 additions & 2 deletions hack/known_types/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func newCommand() *cobra.Command {
imprt := importer.ForCompiler(token.NewFileSet(), "source", nil)
pkg, err := imprt.Import(packagePath)
if err != nil {
return err
return fmt.Errorf("error while importing the package at: %s : %w", packagePath, err)
}

shortPackagePath := strings.TrimPrefix(packagePath, packagePrefix)
Expand Down Expand Up @@ -78,7 +78,7 @@ func init() {%s
}`, strings.Join(mapItems, ""))
if docsOutputPath != "" {
if err = os.WriteFile(docsOutputPath, []byte(strings.Join(docs, "\n")), 0o644); err != nil {
return err
return fmt.Errorf("error while writing to the %s: %w", docsOutputPath, err)
}
}

Expand Down

0 comments on commit 0573ed7

Please sign in to comment.