From 0efa6aab3208a1871860efbb5baeb08f259cd612 Mon Sep 17 00:00:00 2001 From: Adrian Ho Date: Tue, 25 Mar 2025 11:32:23 +0800 Subject: [PATCH] popen: get correct cmd name on error Blindly using args[0] misleads users when an env is passed. Before: ``` ==> go build -ldflags=-s -w -X main.version=1.64.8 -X main.commit=8b37f14 -X main.date=2025-03-17T16:54:02Z ./cmd/golangci-lint brew: command not found: {"SHELL"=>"bash"} Error: Failure while executing; `\{\"SHELL\"=\>\"bash\"\} /opt/homebrew/Cellar/golangci-lint@1/1.64.8/bin/golangci-lint completion bash` exited with 127. Here's the output: ``` After: ``` ==> go build -ldflags=-s -w -X main.version=1.64.8 -X main.commit=8b37f14 -X main.date=2025-03-17T16:54:02Z ./cmd/golangci-lint brew: command not found: /opt/homebrew/Cellar/golangci-lint@1/1.64.8/bin/golangci-lint Error: Failure while executing; `\{\"SHELL\"=\>\"bash\"\} /opt/homebrew/Cellar/golangci-lint@1/1.64.8/bin/golangci-lint completion bash` exited with 127. Here's the output: ``` --- Library/Homebrew/utils/popen.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/utils/popen.rb b/Library/Homebrew/utils/popen.rb index a270ac01c6..83d5be31d0 100644 --- a/Library/Homebrew/utils/popen.rb +++ b/Library/Homebrew/utils/popen.rb @@ -51,13 +51,18 @@ module Utils yield pipe else options[:err] ||= File::NULL unless ENV["HOMEBREW_STDERR"] + cmd = if args[0].is_a? Hash + args[1] + else + args[0] + end begin exec(*args, options) rescue Errno::ENOENT - $stderr.puts "brew: command not found: #{args[0]}" if options[:err] != :close + $stderr.puts "brew: command not found: #{cmd}" if options[:err] != :close exit! 127 rescue SystemCallError - $stderr.puts "brew: exec failed: #{args[0]}" if options[:err] != :close + $stderr.puts "brew: exec failed: #{cmd}" if options[:err] != :close exit! 1 end end