Display error messages for HTTP 400

Review Request #4340 — Created July 17, 2013 and submitted

Information

RBTools
master

Reviewers

The message, displayed on HTTP 400 errors is not very informative now:

ei-grad@ei-grad repos/djblets (master) » post-review --change-description='Exclude "tests" python package from build' -r 4337  
Error getting review request 4337: One or more fields had errors (HTTP 400, API Error 105)

but in debug output we can see, that server provides a better descrition for error:

ei-grad@ei-grad repos/djblets (master) » post-review --change-description='Exclude "tests" python package from build' -r 4337 -d
>>> RBTools 0.5.1
>>> Python 2.7.5 (default, May 12 2013, 12:00:47) 
[GCC 4.8.0 20130502 (prerelease)]
>>> Running on Linux-3.9.9-1-ARCH-x86_64-with-glibc2.2.5
>>> Home = /home/ei-grad
>>> Current Directory = /home/ei-grad/repos/djblets
>>> Checking the repository type. Errors shown below are mostly harmless.
DEBUG:root:Checking for a Subversion repository...
DEBUG:root:Running: svn info Djblets --non-interactive
DEBUG:root:Command exited with rc 1: ['svn', 'info', 'Djblets', '--non-interactive']
svn: E155007: '/home/ei-grad/repos/djblets/Djblets' is not a working copy
---
DEBUG:root:Checking for a Git repository...
DEBUG:root:Running: git rev-parse --git-dir
DEBUG:root:Running: git config core.bare
DEBUG:root:Running: git rev-parse --show-toplevel
DEBUG:root:Running: git symbolic-ref -q HEAD
DEBUG:root:Running: git config --get branch.master.merge
DEBUG:root:Running: git config --get branch.master.remote
DEBUG:root:Running: git config --get remote.origin.url
DEBUG:root:repository info: Path: Djblets, Base path: , Supports changesets: False
>>> Finished checking the repository type.
>>> HTTP GETting api/info/
DEBUG:root:Running: git merge-base origin/master refs/heads/master
DEBUG:root:Running: git diff --no-color --full-index --no-ext-diff --ignore-submodules --no-renames 7b5822c8c3998e357e9db325049d85fc68d392ae..refs/heads/master -M
>>> HTTP GETting api/
>>> HTTP GETting http://reviews.reviewboard.org/api/info/
>>> Using the new web API
>>> HTTP GETting http://reviews.reviewboard.org/api/review-requests/4337/
>>> Attempting to set field 'branch' to 'master' for review request '4337'
>>> HTTP PUTting to http://reviews.reviewboard.org/api/review-requests/4337/draft/: {'branch': 'master'}
>>> Attempting to set field 'changedescription' to 'Exclude "tests" python package from build' for review request '4337'
>>> HTTP PUTting to http://reviews.reviewboard.org/api/review-requests/4337/draft/: {'changedescription': 'Exclude "tests" python package from build'}
>>> Got API Error 105 (HTTP code 400): One or more fields had errors
>>> Error data: {u'fields': {u'changedescription': [u'Change descriptions cannot be used for drafts of new review requests']}, u'stat': u'fail', u'draft': {u'last_updated': u'2013-07-17T20:24:55Z', u'description': u'', u'target_people': [], u'changedescription': u'', u'depends_on': [], u'target_groups': [{u'href': u'http://reviews.reviewboard.org/api/groups/djblets/', u'method': u'GET', u'title': u'djblets'}], u'links': {u'self': {u'href': u'http://reviews.reviewboard.org/api/review-requests/4337/draft/', u'method': u'GET'}, u'update': {u'href': u'http://reviews.reviewboard.org/api/review-requests/4337/draft/', u'method': u'PUT'}, u'draft_screenshots': {u'href': u'http://reviews.reviewboard.org/api/review-requests/4337/draft/screenshots/', u'method': u'GET'}, u'draft_file_attachments': {u'href': u'http://reviews.reviewboard.org/api/review-requests/4337/draft/file-attachments/', u'method': u'GET'}, u'review_request': {u'href': u'http://reviews.reviewboard.org/api/review-requests/4337/', u'method': u'GET', u'title': u'(no summary)'}, u'delete': {u'href': u'http://reviews.reviewboard.org/api/review-requests/4337/draft/', u'method': u'DELETE'}}, u'bugs_closed': [], u'testing_done': u'', u'branch': u'master', u'id': 4975, u'summary': u'', u'public': False}, u'err': {u'msg': u'One or more fields had errors', u'code': 105}}
Error getting review request 4337: One or more fields had errors (HTTP 400, API Error 105)

This patch adds a functionality to display error information from 'fields' member of error response, if there are 'fields' member and if the response HTTP code is 400:

ei-grad@ei-grad repos/djblets (master) » post-review --change-description='Exclude "tests" python package from build' -r 4337
Error getting review request 4337: One or more fields had errors (HTTP 400, API Error 105)
  changedescription: Change descriptions cannot be used for drafts of new review requests

 
reviewbot
  1. This is a review from Review Bot.
      Tool: PEP8 Style Checker
      Processed Files:
        rbtools/postreview.py
        rbtools/api/errors.py
      Ignored Files:
    
    
  2. 
      
reviewbot
  1. This is a review from Review Bot.
      Tool: Pyflakes
      Processed Files:
        rbtools/postreview.py
        rbtools/api/errors.py
      Ignored Files:
    
    
  2. 
      
chipx86
  1. Ship It!
  2. 
      
EI
Review request changed
Status:
Completed
Change Summary:
Pushed to release-0.5.x (3bcb60d)