From 40f76a640a1cb3844501005a35a73114a32fa598 Mon Sep 17 00:00:00 2001
From: Shunsuke Suzuki <suzuki.shunsuke.1989@gmail.com>
Date: Sun, 29 Sep 2024 08:23:19 +0900
Subject: [PATCH] fix(remove): ignore not found commands

---
 pkg/controller/remove/remove.go | 5 +++++
 pkg/controller/which/error.go   | 2 +-
 pkg/controller/which/which.go   | 2 +-
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/pkg/controller/remove/remove.go b/pkg/controller/remove/remove.go
index 6d149a408..c8c537d0c 100644
--- a/pkg/controller/remove/remove.go
+++ b/pkg/controller/remove/remove.go
@@ -12,6 +12,7 @@ import (
 	"github.com/aquaproj/aqua/v2/pkg/config"
 	"github.com/aquaproj/aqua/v2/pkg/config/aqua"
 	"github.com/aquaproj/aqua/v2/pkg/config/registry"
+	"github.com/aquaproj/aqua/v2/pkg/controller/which"
 	"github.com/aquaproj/aqua/v2/pkg/fuzzyfinder"
 	"github.com/sirupsen/logrus"
 	"github.com/spf13/afero"
@@ -161,6 +162,10 @@ func (c *Controller) removeCommands(ctx context.Context, logE *logrus.Entry, par
 		logE := logE.WithField("exe_name", cmd)
 		findResult, err := c.which.Which(ctx, logE, param, cmd)
 		if err != nil {
+			if errors.Is(err, which.ErrCommandIsNotFound) {
+				logE.Debug("the command isn't found")
+				continue
+			}
 			return fmt.Errorf("find a command: %w", err)
 		}
 		if findResult.Package == nil {
diff --git a/pkg/controller/which/error.go b/pkg/controller/which/error.go
index ea47b1d5a..3867656aa 100644
--- a/pkg/controller/which/error.go
+++ b/pkg/controller/which/error.go
@@ -3,6 +3,6 @@ package which
 import "errors"
 
 var (
-	errCommandIsNotFound = errors.New("command is not found")
+	ErrCommandIsNotFound = errors.New("command is not found")
 	errVersionIsRequired = errors.New("version is required")
 )
diff --git a/pkg/controller/which/which.go b/pkg/controller/which/which.go
index 3555732b7..dd58ccbd6 100644
--- a/pkg/controller/which/which.go
+++ b/pkg/controller/which/which.go
@@ -53,7 +53,7 @@ func (c *Controller) Which(ctx context.Context, logE *logrus.Entry, param *confi
 			ExePath: exePath,
 		}, nil
 	}
-	return nil, logerr.WithFields(errCommandIsNotFound, logrus.Fields{ //nolint:wrapcheck
+	return nil, logerr.WithFields(ErrCommandIsNotFound, logrus.Fields{ //nolint:wrapcheck
 		"exe_name": exeName,
 		"doc":      "https://aquaproj.github.io/docs/reference/codes/004",
 	})