summaryrefslogtreecommitdiffstats
path: root/git_config.py
diff options
context:
space:
mode:
authorShawn O. Pearce <sop@google.com>2009-08-22 18:39:49 -0700
committerShawn O. Pearce <sop@google.com>2011-01-09 17:39:22 -0800
commitf00e0ce556fc22fef180c74a9d78f1908d9aeb0b (patch)
tree7ad50d7511c963ec7daae4017849db7b0a06e089 /git_config.py
parent1b5a4a0c5de5fdaa4f8907357a0aa80e365dd199 (diff)
downloadgit-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)
Diffstat (limited to 'git_config.py')
-rw-r--r--git_config.py10
1 files changed, 7 insertions, 3 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:
23except ImportError: 23except ImportError:
24 import dummy_threading as _threading 24 import dummy_threading as _threading
25import time 25import time
26import urllib2
27
26from signal import SIGTERM 28from signal import SIGTERM
27from urllib2 import urlopen, HTTPError 29from urllib2 import urlopen, HTTPError
28from error import GitError, UploadError 30from 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,