diff options
| author | Shawn O. Pearce <sop@google.com> | 2009-08-22 18:39:49 -0700 |
|---|---|---|
| committer | Shawn O. Pearce <sop@google.com> | 2011-01-09 17:39:22 -0800 |
| commit | f00e0ce556fc22fef180c74a9d78f1908d9aeb0b (patch) | |
| tree | 7ad50d7511c963ec7daae4017849db7b0a06e089 | |
| parent | 1b5a4a0c5de5fdaa4f8907357a0aa80e365dd199 (diff) | |
| download | git-repo-f00e0ce556fc22fef180c74a9d78f1908d9aeb0b.tar.gz | |
upload: Catch and cleanly report connectivity errors
Instead of giving a Python backtrace when there is a connectivity
problem during repo upload, report that we cannot access the host,
and why, with a halfway decent error message.
Bug: REPO-45
Change-Id: I9a45b387e86e48073a2d99bd6d594c1a7d6d99d4
Signed-off-by: Shawn O. Pearce <sop@google.com>
(cherry picked from commit d2dfac81ad6a060179b4b2289060af2dc7a5cdfd)
| -rw-r--r-- | git_config.py | 10 | ||||
| -rw-r--r-- | subcmds/upload.py | 10 |
2 files changed, 14 insertions, 6 deletions
diff --git a/git_config.py b/git_config.py index 26fc970b..19c19f19 100644 --- a/git_config.py +++ b/git_config.py | |||
| @@ -23,6 +23,8 @@ try: | |||
| 23 | except ImportError: | 23 | except ImportError: |
| 24 | import dummy_threading as _threading | 24 | import dummy_threading as _threading |
| 25 | import time | 25 | import time |
| 26 | import urllib2 | ||
| 27 | |||
| 26 | from signal import SIGTERM | 28 | from signal import SIGTERM |
| 27 | from urllib2 import urlopen, HTTPError | 29 | from urllib2 import urlopen, HTTPError |
| 28 | from error import GitError, UploadError | 30 | from error import GitError, UploadError |
| @@ -563,23 +565,25 @@ class Remote(object): | |||
| 563 | try: | 565 | try: |
| 564 | info = urlopen(u).read() | 566 | info = urlopen(u).read() |
| 565 | if info == 'NOT_AVAILABLE': | 567 | if info == 'NOT_AVAILABLE': |
| 566 | raise UploadError('Upload over ssh unavailable') | 568 | raise UploadError('%s: SSH disabled' % self.review) |
| 567 | if '<' in info: | 569 | if '<' in info: |
| 568 | # Assume the server gave us some sort of HTML | 570 | # Assume the server gave us some sort of HTML |
| 569 | # response back, like maybe a login page. | 571 | # response back, like maybe a login page. |
| 570 | # | 572 | # |
| 571 | raise UploadError('Cannot read %s:\n%s' % (u, info)) | 573 | raise UploadError('%s: Cannot parse response' % u) |
| 572 | 574 | ||
| 573 | self._review_protocol = 'ssh' | 575 | self._review_protocol = 'ssh' |
| 574 | self._review_host = info.split(" ")[0] | 576 | self._review_host = info.split(" ")[0] |
| 575 | self._review_port = info.split(" ")[1] | 577 | self._review_port = info.split(" ")[1] |
| 578 | except urllib2.URLError, e: | ||
| 579 | raise UploadError('%s: %s' % (self.review, e.reason[1])) | ||
| 576 | except HTTPError, e: | 580 | except HTTPError, e: |
| 577 | if e.code == 404: | 581 | if e.code == 404: |
| 578 | self._review_protocol = 'http-post' | 582 | self._review_protocol = 'http-post' |
| 579 | self._review_host = None | 583 | self._review_host = None |
| 580 | self._review_port = None | 584 | self._review_port = None |
| 581 | else: | 585 | else: |
| 582 | raise UploadError('Cannot guess Gerrit version') | 586 | raise UploadError('Upload over ssh unavailable') |
| 583 | 587 | ||
| 584 | REVIEW_CACHE[u] = ( | 588 | REVIEW_CACHE[u] = ( |
| 585 | self._review_protocol, | 589 | self._review_protocol, |
diff --git a/subcmds/upload.py b/subcmds/upload.py index 1964bffa..20822096 100644 --- a/subcmds/upload.py +++ b/subcmds/upload.py | |||
| @@ -283,15 +283,19 @@ Gerrit Code Review: http://code.google.com/p/gerrit/ | |||
| 283 | have_errors = True | 283 | have_errors = True |
| 284 | 284 | ||
| 285 | print >>sys.stderr, '' | 285 | print >>sys.stderr, '' |
| 286 | print >>sys.stderr, '--------------------------------------------' | 286 | print >>sys.stderr, '----------------------------------------------------------------------' |
| 287 | 287 | ||
| 288 | if have_errors: | 288 | if have_errors: |
| 289 | for branch in todo: | 289 | for branch in todo: |
| 290 | if not branch.uploaded: | 290 | if not branch.uploaded: |
| 291 | print >>sys.stderr, '[FAILED] %-15s %-15s (%s)' % ( | 291 | if len(str(branch.error)) <= 30: |
| 292 | fmt = ' (%s)' | ||
| 293 | else: | ||
| 294 | fmt = '\n (%s)' | ||
| 295 | print >>sys.stderr, ('[FAILED] %-15s %-15s' + fmt) % ( | ||
| 292 | branch.project.relpath + '/', \ | 296 | branch.project.relpath + '/', \ |
| 293 | branch.name, \ | 297 | branch.name, \ |
| 294 | branch.error) | 298 | str(branch.error)) |
| 295 | print >>sys.stderr, '' | 299 | print >>sys.stderr, '' |
| 296 | 300 | ||
| 297 | for branch in todo: | 301 | for branch in todo: |
