From 9bbb6024b2e9ee213bbed1f63ae8ea6063767d5b Mon Sep 17 00:00:00 2001 From: Adrian-George Bostan Date: Tue, 29 Oct 2024 14:30:50 +0200 Subject: [PATCH] Minor error format improvement in pathutil.Create and pathutil.Search --- internal/pathutil/pathutil.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/internal/pathutil/pathutil.go b/internal/pathutil/pathutil.go index 554eda6..981580d 100644 --- a/internal/pathutil/pathutil.go +++ b/internal/pathutil/pathutil.go @@ -4,7 +4,6 @@ import ( "fmt" "os" "path/filepath" - "strings" ) // Unique eliminates the duplicate paths from the provided slice and returns @@ -52,7 +51,6 @@ func First(paths []string) string { // relative to the selected parent path. func Create(name string, paths []string) (string, error) { searchedPaths := make([]string, 0, len(paths)) - for _, p := range paths { p = filepath.Join(p, name) @@ -67,8 +65,8 @@ func Create(name string, paths []string) (string, error) { searchedPaths = append(searchedPaths, dir) } - return "", fmt.Errorf("could not create any of the following paths: %s", - strings.Join(searchedPaths, ", ")) + return "", fmt.Errorf("could not create any of the following paths: %v", + searchedPaths) } // Search searches for the file with the specified `name` in the provided @@ -76,7 +74,6 @@ func Create(name string, paths []string) (string, error) { // but it can also contain a set of parent directories. func Search(name string, paths []string) (string, error) { searchedPaths := make([]string, 0, len(paths)) - for _, p := range paths { p = filepath.Join(p, name) if Exists(p) { @@ -86,8 +83,8 @@ func Search(name string, paths []string) (string, error) { searchedPaths = append(searchedPaths, filepath.Dir(p)) } - return "", fmt.Errorf("could not locate `%s` in any of the following paths: %s", - filepath.Base(name), strings.Join(searchedPaths, ", ")) + return "", fmt.Errorf("could not locate `%s` in any of the following paths: %v", + filepath.Base(name), searchedPaths) } // EnvPath returns the value of the environment variable with the specified