From 56b2a0cab76a107182bede65d29c394ee64aeb78 Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Tue, 10 Aug 2021 13:59:28 +0200 Subject: [PATCH] Wrap err with context instead of logging twice This wraps the errors which are returned instead of logging them, as the returned error is logged at the end of the reconcile run. Signed-off-by: Hidde Beydals --- controllers/gitrepository_controller.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/controllers/gitrepository_controller.go b/controllers/gitrepository_controller.go index 88d662f3..4f24265e 100644 --- a/controllers/gitrepository_controller.go +++ b/controllers/gitrepository_controller.go @@ -398,22 +398,21 @@ func (r *GitRepositoryReconciler) reconcileArtifact(ctx context.Context, obj *so // Ensure target path exists and is a directory if f, err := os.Stat(dir); err != nil { - ctrl.LoggerFrom(ctx).Error(err, "failed to stat source path") + err = fmt.Errorf("failed to stat target path: %w", err) return ctrl.Result{}, err } else if !f.IsDir() { - err := fmt.Errorf("source path '%s' is not a directory", dir) - ctrl.LoggerFrom(ctx).Error(err, "invalid target path") + err = fmt.Errorf("invalid target path: '%s' is not a directory", dir) return ctrl.Result{}, err } // Ensure artifact directory exists and acquire lock if err := r.Storage.MkdirAll(artifact); err != nil { - ctrl.LoggerFrom(ctx).Error(err, "failed to create artifact directory") + err = fmt.Errorf("failed to create artifact directory: %w", err) return ctrl.Result{}, err } unlock, err := r.Storage.Lock(artifact) if err != nil { - ctrl.LoggerFrom(ctx).Error(err, "failed to acquire lock for artifact") + err = fmt.Errorf("failed to acquire lock for artifact: %w", err) return ctrl.Result{}, err } defer unlock()