##// END OF EJS Templates
exception-handling: better handling of remote exception and logging....
marcink -
r171:c608ea73 default
parent child Browse files
Show More
@@ -15,6 +15,8 b''
15 # along with this program; if not, write to the Free Software Foundation,
15 # along with this program; if not, write to the Free Software Foundation,
16 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
18 import sys
19 import traceback
18 import logging
20 import logging
19 import urlparse
21 import urlparse
20
22
@@ -80,3 +82,17 b' def obfuscate_qs(query_string):'
80
82
81 return '&'.join('{}{}'.format(
83 return '&'.join('{}{}'.format(
82 k, '={}'.format(v) if v else '') for k, v in parsed)
84 k, '={}'.format(v) if v else '') for k, v in parsed)
85
86
87 def raise_from_original(new_type):
88 """
89 Raise a new exception type with original args and traceback.
90 """
91 exc_type, exc_value, exc_traceback = sys.exc_info()
92
93 traceback.format_exception(exc_type, exc_value, exc_traceback)
94
95 try:
96 raise new_type(*exc_value.args), None, exc_traceback
97 finally:
98 del exc_traceback
@@ -35,7 +35,7 b' from dulwich.server import update_server'
35
35
36 from vcsserver import exceptions, settings, subprocessio
36 from vcsserver import exceptions, settings, subprocessio
37 from vcsserver.utils import safe_str
37 from vcsserver.utils import safe_str
38 from vcsserver.base import RepoFactory, obfuscate_qs
38 from vcsserver.base import RepoFactory, obfuscate_qs, raise_from_original
39 from vcsserver.hgcompat import (
39 from vcsserver.hgcompat import (
40 hg_url as url_parser, httpbasicauthhandler, httpdigestauthhandler)
40 hg_url as url_parser, httpbasicauthhandler, httpdigestauthhandler)
41
41
@@ -58,6 +58,11 b' def reraise_safe_exceptions(func):'
58 raise exceptions.LookupException(e.message)
58 raise exceptions.LookupException(e.message)
59 except (HangupException, UnexpectedCommandError) as e:
59 except (HangupException, UnexpectedCommandError) as e:
60 raise exceptions.VcsException(e.message)
60 raise exceptions.VcsException(e.message)
61 except Exception as e:
62 if not hasattr(e, '_vcs_kind'):
63 log.exception("Unhandled exception in git remote call")
64 raise_from_original(exceptions.UnhandledException)
65 raise
61 return wrapper
66 return wrapper
62
67
63
68
@@ -18,7 +18,6 b''
18 import io
18 import io
19 import logging
19 import logging
20 import stat
20 import stat
21 import sys
22 import urllib
21 import urllib
23 import urllib2
22 import urllib2
24
23
@@ -28,7 +27,7 b' from mercurial import commands'
28 from mercurial import unionrepo
27 from mercurial import unionrepo
29
28
30 from vcsserver import exceptions
29 from vcsserver import exceptions
31 from vcsserver.base import RepoFactory, obfuscate_qs
30 from vcsserver.base import RepoFactory, obfuscate_qs, raise_from_original
32 from vcsserver.hgcompat import (
31 from vcsserver.hgcompat import (
33 archival, bin, clone, config as hgconfig, diffopts, hex,
32 archival, bin, clone, config as hgconfig, diffopts, hex,
34 hg_url as url_parser, httpbasicauthhandler, httpdigestauthhandler,
33 hg_url as url_parser, httpbasicauthhandler, httpdigestauthhandler,
@@ -91,17 +90,6 b' def reraise_safe_exceptions(func):'
91 return wrapper
90 return wrapper
92
91
93
92
94 def raise_from_original(new_type):
95 """
96 Raise a new exception type with original args and traceback.
97 """
98 _, original, traceback = sys.exc_info()
99 try:
100 raise new_type(*original.args), None, traceback
101 finally:
102 del traceback
103
104
105 class MercurialFactory(RepoFactory):
93 class MercurialFactory(RepoFactory):
106
94
107 def _create_config(self, config, hooks=True):
95 def _create_config(self, config, hooks=True):
@@ -17,12 +17,14 b''
17 # along with this program; if not, write to the Free Software Foundation,
17 # along with this program; if not, write to the Free Software Foundation,
18 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
19
20 import io
21 import sys
22 import json
23 import logging
20 import collections
24 import collections
21 import importlib
25 import importlib
22 import io
23 import json
24 import subprocess
26 import subprocess
25 import sys
27
26 from httplib import HTTPConnection
28 from httplib import HTTPConnection
27
29
28
30
@@ -33,6 +35,8 b' import simplejson as json'
33
35
34 from vcsserver import exceptions
36 from vcsserver import exceptions
35
37
38 log = logging.getLogger(__name__)
39
36
40
37 class HooksHttpClient(object):
41 class HooksHttpClient(object):
38 connection = None
42 connection = None
@@ -105,6 +109,11 b' class GitMessageWriter(RemoteMessageWrit'
105
109
106 def _handle_exception(result):
110 def _handle_exception(result):
107 exception_class = result.get('exception')
111 exception_class = result.get('exception')
112 exception_traceback = result.get('exception_traceback')
113
114 if exception_traceback:
115 log.error('Got traceback from remote call:%s', exception_traceback)
116
108 if exception_class == 'HTTPLockedRC':
117 if exception_class == 'HTTPLockedRC':
109 raise exceptions.RepositoryLockedException(*result['exception_args'])
118 raise exceptions.RepositoryLockedException(*result['exception_args'])
110 elif exception_class == 'RepositoryError':
119 elif exception_class == 'RepositoryError':
@@ -33,7 +33,7 b' import svn.repos'
33
33
34 from vcsserver import svn_diff
34 from vcsserver import svn_diff
35 from vcsserver import exceptions
35 from vcsserver import exceptions
36 from vcsserver.base import RepoFactory
36 from vcsserver.base import RepoFactory, raise_from_original
37
37
38
38
39 log = logging.getLogger(__name__)
39 log = logging.getLogger(__name__)
@@ -62,17 +62,6 b' def reraise_safe_exceptions(func):'
62 return wrapper
62 return wrapper
63
63
64
64
65 def raise_from_original(new_type):
66 """
67 Raise a new exception type with original args and traceback.
68 """
69 _, original, traceback = sys.exc_info()
70 try:
71 raise new_type(*original.args), None, traceback
72 finally:
73 del traceback
74
75
76 class SubversionFactory(RepoFactory):
65 class SubversionFactory(RepoFactory):
77
66
78 def _create_repo(self, wire, create, compatible_version):
67 def _create_repo(self, wire, create, compatible_version):
General Comments 0
You need to be logged in to leave comments. Login now