Skip to content

Commit

Permalink
Minor error format improvement in pathutil.Create and pathutil.Search
Browse files Browse the repository at this point in the history
  • Loading branch information
adrg committed Oct 29, 2024
1 parent 987b3ce commit 9bbb602
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions internal/pathutil/pathutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
)

// Unique eliminates the duplicate paths from the provided slice and returns
Expand Down Expand Up @@ -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)

Expand All @@ -67,16 +65,15 @@ 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
// slice of `paths`. The `name` parameter must contain the name of the file,
// 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) {
Expand All @@ -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
Expand Down

0 comments on commit 9bbb602

Please sign in to comment.