aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/test/utils/popen_spec.rb6
-rw-r--r--Library/Homebrew/utils/popen.rb10
2 files changed, 15 insertions, 1 deletions
diff --git a/Library/Homebrew/test/utils/popen_spec.rb b/Library/Homebrew/test/utils/popen_spec.rb
index 63bbc7b18..d1ae12d1c 100644
--- a/Library/Homebrew/test/utils/popen_spec.rb
+++ b/Library/Homebrew/test/utils/popen_spec.rb
@@ -15,6 +15,12 @@ describe Utils do
).to eq("success")
expect($CHILD_STATUS).to be_a_success
end
+
+ it "fails when the command does not exist" do
+ expect(subject.popen_read("./nonexistent", err: :out))
+ .to eq("brew: command not found: ./nonexistent\n")
+ expect($CHILD_STATUS).to be_a_failure
+ end
end
describe "::popen_write" do
diff --git a/Library/Homebrew/utils/popen.rb b/Library/Homebrew/utils/popen.rb
index 2fa3ade46..21dceec06 100644
--- a/Library/Homebrew/utils/popen.rb
+++ b/Library/Homebrew/utils/popen.rb
@@ -14,7 +14,15 @@ module Utils
yield pipe
else
options[:err] ||= :close unless ENV["HOMEBREW_STDERR"]
- exec(*args, options)
+ begin
+ exec(*args, options)
+ rescue Errno::ENOENT
+ $stderr.puts "brew: command not found: #{args[0]}" unless options[:err] == :close
+ exit! 127
+ rescue SystemCallError
+ $stderr.puts "brew: exec failed: #{args[0]}" unless options[:err] == :close
+ exit! 1
+ end
end
end
end