Skip to content

Commit

Permalink
chore: wrap error objects to include context (#10904)
Browse files Browse the repository at this point in the history
Signed-off-by: Jiayi Lu <jiayi_lu@intuit.com>

Signed-off-by: Jiayi Lu <jiayi_lu@intuit.com>
  • Loading branch information
someOne404 committed Oct 12, 2022
1 parent 4583cca commit b5d8d5a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions applicationset/controllers/applicationset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ func (r *ApplicationSetReconciler) SetupWithManager(mgr ctrl.Manager) error {
// ...and if so, return it
return []string{owner.Name}
}); err != nil {
return err
return fmt.Errorf("error setting up with manager: %w", err)
}

return ctrl.NewControllerManagedBy(mgr).
Expand Down Expand Up @@ -567,7 +567,7 @@ func (r *ApplicationSetReconciler) createInCluster(ctx context.Context, applicat
var createApps []argov1alpha1.Application
current, err := r.getCurrentApplications(ctx, applicationSet)
if err != nil {
return err
return fmt.Errorf("error getting current applications: %w", err)
}

m := make(map[string]bool) // Will holds the app names that are current in the cluster
Expand Down Expand Up @@ -608,13 +608,13 @@ func (r *ApplicationSetReconciler) deleteInCluster(ctx context.Context, applicat
// clusterList, err := argoDB.ListClusters(ctx)
clusterList, err := utils.ListClusters(ctx, r.KubeClientset, applicationSet.Namespace)
if err != nil {
return err
return fmt.Errorf("error listing clusters: %w", err)
}

// Save current applications to be able to delete the ones that are not in appList
current, err := r.getCurrentApplications(ctx, applicationSet)
if err != nil {
return err
return fmt.Errorf("error getting current applications: %w", err)
}

m := make(map[string]bool) // Will holds the app names in appList for the deletion process
Expand Down Expand Up @@ -718,7 +718,7 @@ func (r *ApplicationSetReconciler) removeFinalizerOnInvalidDestination(ctx conte

err := r.Client.Update(ctx, app, &client.UpdateOptions{})
if err != nil {
return err
return fmt.Errorf("error updating finalizers: %w", err)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/util/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func readProjFromURI(fileURL string, proj *v1alpha1.AppProject) error {
} else {
err = config.UnmarshalRemoteFile(fileURL, &proj)
}
return err
return fmt.Errorf("error reading proj from uri: %w", err)
}

func SetProjSpecOptions(flags *pflag.FlagSet, spec *v1alpha1.AppProjectSpec, projOpts *ProjectOpts) int {
Expand Down
8 changes: 4 additions & 4 deletions util/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,26 +276,26 @@ func getWebUrlRegex(webURL string) (*regexp.Regexp, error) {
func (a *ArgoCDWebhookHandler) storePreviouslyCachedManifests(app *v1alpha1.Application, change changeInfo, trackingMethod string, appInstanceLabelKey string) error {
err := argo.ValidateDestination(context.Background(), &app.Spec.Destination, a.db)
if err != nil {
return err
return fmt.Errorf("error validating destination: %w", err)
}

var clusterInfo v1alpha1.ClusterInfo
err = a.serverCache.GetClusterInfo(app.Spec.Destination.Server, &clusterInfo)
if err != nil {
return err
return fmt.Errorf("error getting cluster info: %w", err)
}

cache.LogDebugManifestCacheKeyFields("getting manifests cache", "webhook app revision changed", change.shaBefore, &app.Spec.Source, &clusterInfo, app.Spec.Destination.Namespace, trackingMethod, appInstanceLabelKey, app.Name)

var cachedManifests cache.CachedManifestResponse
if err := a.repoCache.GetManifests(change.shaBefore, &app.Spec.Source, &clusterInfo, app.Spec.Destination.Namespace, trackingMethod, appInstanceLabelKey, app.Name, &cachedManifests); err != nil {
return err
return fmt.Errorf("error getting manifests: %w", err)
}

cache.LogDebugManifestCacheKeyFields("setting manifests cache", "webhook app revision changed", change.shaAfter, &app.Spec.Source, &clusterInfo, app.Spec.Destination.Namespace, trackingMethod, appInstanceLabelKey, app.Name)

if err = a.repoCache.SetManifests(change.shaAfter, &app.Spec.Source, &clusterInfo, app.Spec.Destination.Namespace, trackingMethod, appInstanceLabelKey, app.Name, &cachedManifests); err != nil {
return err
return fmt.Errorf("error setting manifests: %w", err)
}
return nil
}
Expand Down

0 comments on commit b5d8d5a

Please sign in to comment.