From ea7415237c33744a00c6b27aebfa42416a0b01d1 Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Sun, 16 Feb 2014 22:24:33 -0500 Subject: [PATCH] Add helpful error message for authentication failures --- Library/Homebrew/utils.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 4bf9dbcc47..63eeff3fa8 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -253,7 +253,6 @@ module GitHub extend self Error = Class.new(RuntimeError) HTTPNotFoundError = Class.new(Error) - AuthenticationFailedError = Class.new(Error) class RateLimitExceededError < Error def initialize(reset, error) @@ -274,6 +273,16 @@ module GitHub extend self end end + class AuthenticationFailedError < Error + def initialize(error) + super <<-EOS.undent + GitHub #{error} + HOMEBREW_GITHUB_API_TOKEN may be invalid or expired, check: + https://github.com/settings/applications + EOS + end + end + def open url, headers={}, &block # This is a no-op if the user is opting out of using the GitHub API. return if ENV['HOMEBREW_NO_GITHUB_API'] @@ -306,7 +315,7 @@ module GitHub extend self case e.io.status.first when "401", "403" - raise AuthenticationFailedError, e.message, e.backtrace + raise AuthenticationFailedError.new(e.message) when "404" raise HTTPNotFoundError, e.message, e.backtrace else