Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve error logs #10944

Merged
merged 19 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion applicationset/utils/createOrUpdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func CreateOrUpdate(ctx context.Context, c client.Client, obj client.Object, f c
// mutate wraps a MutateFn and applies validation to its result
func mutate(f controllerutil.MutateFn, key client.ObjectKey, obj client.Object) error {
if err := f(); err != nil {
return err
return fmt.Errorf("error while wrapping using MutateFn: %w", err)
}
if newKey := client.ObjectKeyFromObject(obj); key != newKey {
return fmt.Errorf("MutateFn cannot mutate object name and/or object namespace")
Expand Down
4 changes: 2 additions & 2 deletions cmd/argocd/commands/admin/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,11 @@ func saveToFile(err error, outputFormat string, result reconcileResults, outputP
switch outputFormat {
case "yaml":
if data, err = yaml.Marshal(result); err != nil {
return err
return fmt.Errorf("error marshalling yaml: %w", err)
}
case "json":
if data, err = json.Marshal(result); err != nil {
return err
return fmt.Errorf("error marshalling json: %w", err)
}
default:
return fmt.Errorf("format %s is not supported", outputFormat)
Expand Down
6 changes: 3 additions & 3 deletions cmd/argocd/commands/admin/generatespec_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func PrintResources(output string, out io.Writer, resources ...interface{}) erro
}
filteredResource, err := omitFields(resource)
if err != nil {
return err
return fmt.Errorf("error omitting filtered fields from the resource: %w", err)
}
resources[i] = filteredResource
}
Expand All @@ -56,14 +56,14 @@ func PrintResources(output string, out io.Writer, resources ...interface{}) erro
case "json":
jsonBytes, err := json.MarshalIndent(obj, "", " ")
if err != nil {
return err
return fmt.Errorf("error marshaling json: %w", err)
}

_, _ = fmt.Fprintln(out, string(jsonBytes))
case "yaml":
yamlBytes, err := yaml.Marshal(obj)
if err != nil {
return err
return fmt.Errorf("error marshaling yaml: %w", err)
}
// marshaled YAML already ends with the new line character
_, _ = fmt.Fprint(out, string(yamlBytes))
Expand Down
8 changes: 4 additions & 4 deletions cmd/argocd/commands/admin/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ func saveProject(ctx context.Context, updated v1alpha1.AppProject, orig v1alpha1
errors.CheckError(err)
live, err := kube.ToUnstructured(&orig)
if err != nil {
return err
return fmt.Errorf("error converting project to unstructured: %w", err)
}
_ = cli.PrintDiff(updated.Name, target, live)
if !dryRun {
_, err = projectsIf.Update(ctx, &updated, v1.UpdateOptions{})
if err != nil {
return err
return fmt.Errorf("error while updating project: %w", err)
}
}
return nil
Expand Down Expand Up @@ -188,7 +188,7 @@ func NewUpdatePolicyRuleCommand() *cobra.Command {
func updateProjects(ctx context.Context, projIf appclient.AppProjectInterface, projectGlob string, rolePattern string, action string, modification func(string, string) string, dryRun bool) error {
projects, err := projIf.List(ctx, v1.ListOptions{})
if err != nil {
return err
return fmt.Errorf("error listing the projects: %w", err)
}
for _, proj := range projects.Items {
if !globMatch(projectGlob, proj.Name) {
Expand Down Expand Up @@ -225,7 +225,7 @@ func updateProjects(ctx context.Context, projIf appclient.AppProjectInterface, p
if updated {
err = saveProject(ctx, proj, *origProj, projIf, dryRun)
if err != nil {
return err
return fmt.Errorf("error saving the project: %w", err)
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/util/applicationset.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func readAppsetFromURI(fileURL string, appset *[]*argoprojiov1alpha1.Application

yml, err := readFilePayload()
if err != nil {
return err
return fmt.Errorf("error reading file payload: %w", err)
}

return readAppset(yml, appset)
Expand All @@ -49,18 +49,18 @@ func readAppsetFromURI(fileURL string, appset *[]*argoprojiov1alpha1.Application
func readAppset(yml []byte, appsets *[]*argoprojiov1alpha1.ApplicationSet) error {
yamls, err := kube.SplitYAMLToString(yml)
if err != nil {
return err
return fmt.Errorf("error splitting YAML to string: %w", err)
}

for _, yml := range yamls {
var appset argoprojiov1alpha1.ApplicationSet
err = config.Unmarshal([]byte(yml), &appset)
if err != nil {
return err
return fmt.Errorf("error unmarshalling appset: %w", err)
}
*appsets = append(*appsets, &appset)

}

return err
return fmt.Errorf("error reading app set: %w", err)
}
4 changes: 2 additions & 2 deletions controller/clusterinfoupdater.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package controller
import (
"context"
"time"

"fmt"
"github.com/argoproj/gitops-engine/pkg/cache"
"github.com/argoproj/gitops-engine/pkg/utils/kube"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -93,7 +93,7 @@ func (c *clusterInfoUpdater) updateClusters() {
func (c *clusterInfoUpdater) updateClusterInfo(cluster appv1.Cluster, info *cache.ClusterInfo) error {
apps, err := c.appLister.List(labels.Everything())
if err != nil {
return err
return fmt.Errorf("error while fetching the apps list: %w", err)
}
var appCount int64
for _, a := range apps {
Expand Down