diff options
| author | Shawn O. Pearce <sop@google.com> | 2009-08-22 18:39:49 -0700 |
|---|---|---|
| committer | Shawn O. Pearce <sop@google.com> | 2009-08-22 18:41:16 -0700 |
| commit | d2dfac81ad6a060179b4b2289060af2dc7a5cdfd (patch) | |
| tree | c783e72b72e7c199ef39d036bb94ca15ec7c59ec | |
| parent | 47199010671a6724e18f061f4da63dcd46e3f354 (diff) | |
| download | git-repo-d2dfac81ad6a060179b4b2289060af2dc7a5cdfd.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>
| -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 9dba699a..b6288219 100644 --- a/git_config.py +++ b/git_config.py | |||
| @@ -19,6 +19,8 @@ import re | |||
| 19 | import subprocess | 19 | import subprocess |
| 20 | import sys | 20 | import sys |
| 21 | import time | 21 | import time |
| 22 | import urllib2 | ||
| 23 | |||
| 22 | from signal import SIGTERM | 24 | from signal import SIGTERM |
| 23 | from urllib2 import urlopen, HTTPError | 25 | from urllib2 import urlopen, HTTPError |
| 24 | from error import GitError, UploadError | 26 | from error import GitError, UploadError |
| @@ -487,23 +489,25 @@ class Remote(object): | |||
| 487 | try: | 489 | try: |
| 488 | info = urlopen(u).read() | 490 | info = urlopen(u).read() |
| 489 | if info == 'NOT_AVAILABLE': | 491 | if info == 'NOT_AVAILABLE': |
| 490 | raise UploadError('Upload over ssh unavailable') | 492 | raise UploadError('%s: SSH disabled' % self.review) |
| 491 | if '<' in info: | 493 | if '<' in info: |
| 492 | # Assume the server gave us some sort of HTML | 494 | # Assume the server gave us some sort of HTML |
| 493 | # response back, like maybe a login page. | 495 | # response back, like maybe a login page. |
| 494 | # | 496 | # |
| 495 | raise UploadError('Cannot read %s:\n%s' % (u, info)) | 497 | raise UploadError('%s: Cannot parse response' % u) |
| 496 | 498 | ||
| 497 | self._review_protocol = 'ssh' | 499 | self._review_protocol = 'ssh' |
| 498 | self._review_host = info.split(" ")[0] | 500 | self._review_host = info.split(" ")[0] |
| 499 | self._review_port = info.split(" ")[1] | 501 | self._review_port = info.split(" ")[1] |
| 502 | except urllib2.URLError, e: | ||
| 503 | raise UploadError('%s: %s' % (self.review, e.reason[1])) | ||
| 500 | except HTTPError, e: | 504 | except HTTPError, e: |
| 501 | if e.code == 404: | 505 | if e.code == 404: |
| 502 | self._review_protocol = 'http-post' | 506 | self._review_protocol = 'http-post' |
| 503 | self._review_host = None | 507 | self._review_host = None |
| 504 | self._review_port = None | 508 | self._review_port = None |
| 505 | else: | 509 | else: |
| 506 | raise UploadError('Cannot guess Gerrit version') | 510 | raise UploadError('Upload over ssh unavailable') |
| 507 | 511 | ||
| 508 | REVIEW_CACHE[u] = ( | 512 | REVIEW_CACHE[u] = ( |
| 509 | self._review_protocol, | 513 | self._review_protocol, |
diff --git a/subcmds/upload.py b/subcmds/upload.py index 8e3d2723..2ab6a484 100644 --- a/subcmds/upload.py +++ b/subcmds/upload.py | |||
| @@ -273,15 +273,19 @@ Gerrit Code Review: http://code.google.com/p/gerrit/ | |||
| 273 | have_errors = True | 273 | have_errors = True |
| 274 | 274 | ||
| 275 | print >>sys.stderr, '' | 275 | print >>sys.stderr, '' |
| 276 | print >>sys.stderr, '--------------------------------------------' | 276 | print >>sys.stderr, '----------------------------------------------------------------------' |
| 277 | 277 | ||
| 278 | if have_errors: | 278 | if have_errors: |
| 279 | for branch in todo: | 279 | for branch in todo: |
| 280 | if not branch.uploaded: | 280 | if not branch.uploaded: |
| 281 | print >>sys.stderr, '[FAILED] %-15s %-15s (%s)' % ( | 281 | if len(str(branch.error)) <= 30: |
| 282 | fmt = ' (%s)' | ||
| 283 | else: | ||
| 284 | fmt = '\n (%s)' | ||
| 285 | print >>sys.stderr, ('[FAILED] %-15s %-15s' + fmt) % ( | ||
| 282 | branch.project.relpath + '/', \ | 286 | branch.project.relpath + '/', \ |
| 283 | branch.name, \ | 287 | branch.name, \ |
| 284 | branch.error) | 288 | str(branch.error)) |
| 285 | print >>sys.stderr, '' | 289 | print >>sys.stderr, '' |
| 286 | 290 | ||
| 287 | for branch in todo: | 291 | for branch in todo: |
