Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better handle missing environment variables when updating #5529

Merged
merged 1 commit into from
Jan 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion Library/Homebrew/brew.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,21 @@
raise "Homebrew must be run under Ruby 2.3! You're running #{RUBY_VERSION}."
end

require_relative "global"
begin
require_relative "global"
rescue MissingEnvironmentVariables => e
raise e if ENV["HOMEBREW_MISSING_ENV_RETRY"]

if ENV["HOMEBREW_DEVELOPER"]
$stderr.puts <<~EOS
Warning: #{e.message}
Retrying with `exec #{ENV["HOMEBREW_BREW_FILE"]}`!
EOS
end

ENV["HOMEBREW_MISSING_ENV_RETRY"] = "1"
exec ENV["HOMEBREW_BREW_FILE"], *ARGV
end

begin
trap("INT", std_trap) # restore default CTRL-C handler
Expand Down
22 changes: 11 additions & 11 deletions Library/Homebrew/config.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
def get_env_or_raise(env, message = nil)
message ||= <<~EOS
don't worry, you likely hit a bug auto-updating from an old version.
Rerun your command, everything is up-to-date and fine now
EOS
unless ENV["HOMEBREW_BREW_FILE"]
raise "HOMEBREW_BREW_FILE was not exported! Please call bin/brew directly!"
end

# Path to `bin/brew` main executable in `HOMEBREW_PREFIX`
HOMEBREW_BREW_FILE = Pathname.new(ENV["HOMEBREW_BREW_FILE"])

class MissingEnvironmentVariables < RuntimeError; end

def get_env_or_raise(env)
unless ENV[env]
abort <<~EOS
Error: #{env} was not exported!\nPlease #{message.chomp}.
EOS
raise MissingEnvironmentVariables, "#{env} was not exported!"
end
ENV[env]
end

# Path to `bin/brew` main executable in `HOMEBREW_PREFIX`
HOMEBREW_BREW_FILE = Pathname.new(get_env_or_raise("HOMEBREW_BREW_FILE", "call bin/brew directly"))

# Where we link under
HOMEBREW_PREFIX = Pathname.new(get_env_or_raise("HOMEBREW_PREFIX"))

Expand Down