Skip to content

Commit

Permalink
commands.rb: Extend 'display_api_exception' to print error messages
Browse files Browse the repository at this point in the history
So you can see what GitHub is complaining about.  For example,

  $ hub merge-button https://github.com/defunkt/hub/pull/9999999999
  Error pushing merge button: Not Found (HTTP 404)
  #<Net::HTTPNotFound:0x7f4cf845c670>
  {"message":"Not Found"}

This was useful for debugging, when I originally thought that the
whole PUT body was optional if you didn't want to specify
'commit_message'.  In that case, I got:

  $ hub merge-button wking/email-issue-reply-testing#2
  Error pushing merge button: Bad Request (HTTP 400)
  #<Net::HTTPBadRequest:0x7f944f75a450>
  {"message":"Body should be a JSON Hash"}

Which is a lot more helpful than just "Bad Request".  It would be nice
if the 'Net::HTTP*' object hash was not printed, but I lack sufficient
Ruby-foo to know how to do that.
  • Loading branch information
wking committed Jan 25, 2013
1 parent 1dcd569 commit 95f45ee
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/hub/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ def merge_button(args)
args.executable = 'echo'
args.replace ['merged', '%s#%s' % [project.name_with_owner, pull_id]]
rescue GitHubAPI::Exceptions
display_api_exception("pushing merge button", $!.response)
display_api_exception("pushing merge button", $!.response, $!.data)
exit 1
end

Expand Down Expand Up @@ -1048,8 +1048,11 @@ def expand_alias(cmd)
end
end

def display_api_exception(action, response)
def display_api_exception(action, response, message=nil)
$stderr.puts "Error #{action}: #{response.message.strip} (HTTP #{response.status})"
if message
$stderr.puts message
end
if 422 == response.status and response.error_message?
# display validation errors
msg = response.error_message
Expand Down

0 comments on commit 95f45ee

Please sign in to comment.