From 3743955d6d3305246771d01e1d2b17116345c165 Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Fri, 27 Oct 2023 10:12:30 +0200 Subject: [PATCH] compose: try all possible providers before throwing an error Do not error out immediately but collect all errors and report them if no candidate succeeded. That'll fix #20502 and improve the quality of reported errors. [NO NEW TESTS NEEDED] Fixes: #20502 Signed-off-by: Valentin Rothberg --- cmd/podman/compose.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/cmd/podman/compose.go b/cmd/podman/compose.go index 1af7f129cf..4a74d35df9 100644 --- a/cmd/podman/compose.go +++ b/cmd/podman/compose.go @@ -17,6 +17,7 @@ import ( "github.com/containers/common/pkg/config" "github.com/containers/podman/v4/cmd/podman/registry" + "github.com/containers/podman/v4/pkg/errorhandling" "github.com/containers/podman/v4/pkg/machine" "github.com/containers/podman/v4/pkg/machine/provider" "github.com/sirupsen/logrus" @@ -85,20 +86,19 @@ func composeProvider() (string, error) { return "", errors.New("no compose provider specified, please refer to `man podman-compose` for details") } + lookupErrors := make([]error, 0, len(candidates)) for _, candidate := range candidates { path, err := exec.LookPath(os.ExpandEnv(candidate)) - if err != nil { - if errors.Is(err, os.ErrNotExist) { - continue - } - return "", err + if err == nil { + // First specified provider "candidate" wins. + logrus.Debugf("Found compose provider %q", path) + return path, nil } - // First specified provider "candidate" wins. - logrus.Debugf("Found compose provider %q", path) - return path, nil + logrus.Debugf("Error looking up compose provider %q: %v", path, err) + lookupErrors = append(lookupErrors, err) } - return "", errors.New("no configured compose provider found on system, please refer to the documentation for details") + return "", fmt.Errorf("looking up compose provider failed\n%v", errorhandling.JoinErrors(lookupErrors)) } // composeDockerHost returns the value to be set in the DOCKER_HOST environment