Skip to content

Commit c9049ea

Browse files
authored
fix: print all error output to stderr when shim can't be resolved (#2109)
1 parent 392d09a commit c9049ea

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

.tool-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
golang 1.23.4
22
bats 1.8.2
3-
shellcheck 0.9.0
3+
shellcheck 0.10.0
44
shfmt 3.6.0

cmd/asdf/main_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"os/exec"
66
"strings"
77
"testing"
8+
9+
"github.com/asdf-vm/asdf/internal/execute"
810
)
911

1012
// Basic integration tests using the legacy BATS test scripts. This ensures the
@@ -124,9 +126,7 @@ func runBatsFile(t *testing.T, dir, filename string) {
124126
cmd.Stderr = &stderr
125127

126128
// Add dir to asdf test variables
127-
asdfTestHome := fmt.Sprintf("BASE_DIR=%s", dir)
128-
asdfBinPath := fmt.Sprintf("ASDF_BIN=%s", dir)
129-
cmd.Env = []string{asdfBinPath, asdfTestHome}
129+
cmd.Env = execute.MergeWithCurrentEnv(map[string]string{"BASE_DIR": dir, "ASDF_BIN": dir})
130130

131131
err := cmd.Run()
132132
if err != nil {

internal/cli/cli.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -666,16 +666,16 @@ func getExecutable(logger *log.Logger, conf config.Config, command string) (exec
666666
logger.Printf("No preset version installed for command %s", command)
667667
for _, toolVersion := range toolVersions {
668668
for _, version := range toolVersion.Versions {
669-
fmt.Printf("asdf install %s %s\n", toolVersion.Name, version)
669+
logger.Printf("asdf install %s %s\n", toolVersion.Name, version)
670670
}
671671
}
672672

673-
fmt.Printf("or add one of the following versions in your config file at %s/.tool-versions\n", currentDir)
673+
logger.Printf("or add one of the following versions in your config file at %s/.tool-versions\n", currentDir)
674674
}
675675

676676
for _, toolVersion := range toolVersions {
677677
for _, version := range toolVersion.Versions {
678-
fmt.Printf("%s %s\n", toolVersion.Name, version)
678+
logger.Printf("%s %s\n", toolVersion.Name, version)
679679
}
680680
}
681681
}

test/shim_exec.bats

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,14 @@ teardown() {
8888

8989
touch "$PROJECT_DIR/.tool-versions"
9090

91-
run "$ASDF_DIR/shims/dummy" world hello
91+
run --separate-stderr "$ASDF_DIR/shims/dummy" world hello
9292
[ "$status" -eq 126 ]
9393

94-
echo "$output" | grep -q "No version is set for command dummy" 2>/dev/null
95-
echo "$output" | grep -q "Consider adding one of the following versions in your config file at $PROJECT_DIR/.tool-versions" 2>/dev/null
96-
echo "$output" | grep -q "dummy 1.0" 2>/dev/null
97-
echo "$output" | grep -q "dummy 2.0.0" 2>/dev/null
94+
# shellcheck disable=SC2154
95+
echo "${stderr:?}" | grep -q "No version is set for command dummy" 2>/dev/null
96+
echo "${stderr:?}" | grep -q "Consider adding one of the following versions in your config file at $PROJECT_DIR/.tool-versions" 2>/dev/null
97+
echo "${stderr:?}" | grep -q "dummy 1.0" 2>/dev/null
98+
echo "${stderr:?}" | grep -q "dummy 2.0.0" 2>/dev/null
9899
}
99100

100101
@test "shim exec should suggest different plugins providing same tool when no version is selected" {

0 commit comments

Comments
 (0)