mirror of
https://github.com/facebook/sapling.git
synced 2024-10-12 01:39:21 +03:00
remotefilelog: move edenapi error logging into dedicated function
Summary: We need to log (and in debug mode print out) Eden API exceptions in several places in the code. Let's factor out this logic into a function in the edenapi module. Reviewed By: xavierd Differential Revision: D16027147 fbshipit-source-id: 76c8e97dcaaa114e0c22448d117caae948fb60f4
This commit is contained in:
parent
367a4a7cea
commit
2bd15eca26
@ -477,17 +477,7 @@ def setupclient(ui, repo):
|
||||
except Exception as e:
|
||||
ui.warn(_("failed to initialize Eden API client;"))
|
||||
ui.warn(_(" disabling HTTPS data fetching\n"))
|
||||
|
||||
if edenapi.debug(ui):
|
||||
ui.warn(_("exception: %s\n") % str(e))
|
||||
|
||||
ui.log(
|
||||
"edenapi_error",
|
||||
exception_msg=str(e),
|
||||
exception_type=type(e).__name__,
|
||||
traceback=traceback.format_exc(),
|
||||
)
|
||||
|
||||
edenapi.logexception(ui, e)
|
||||
edenapi._disabled = True
|
||||
|
||||
|
||||
|
@ -5,6 +5,8 @@
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import traceback
|
||||
|
||||
from edenscm.mercurial import error, httpconnection
|
||||
from edenscm.mercurial.i18n import _
|
||||
from edenscmnative.bindings import edenapi
|
||||
@ -30,6 +32,22 @@ def bailifdisabled(ui):
|
||||
raise error.Abort(_("HTTPS data fetching is disabled"))
|
||||
|
||||
|
||||
def logexception(ui, exc):
|
||||
"""Log an exception to Mercurial's telemetry and print a user warning."""
|
||||
exctype = type(exc).__name__
|
||||
excmsg = str(exc)
|
||||
|
||||
if debug(ui):
|
||||
ui.warn("%s: %s\n" % (exctype, excmsg))
|
||||
|
||||
ui.log(
|
||||
"edenapi_error",
|
||||
exception_msg=excmsg,
|
||||
exception_type=exctype,
|
||||
traceback=traceback.format_exc(),
|
||||
)
|
||||
|
||||
|
||||
def _getbaseurl(ui):
|
||||
"""Get the base URL of the API server."""
|
||||
url = ui.config("edenapi", "url")
|
||||
|
@ -704,17 +704,7 @@ class fileserverclient(object):
|
||||
except Exception as e:
|
||||
self.ui.warn(_("encountered error during HTTPS fetching;"))
|
||||
self.ui.warn(_(" falling back to SSH\n"))
|
||||
|
||||
if edenapi.debug(self.ui):
|
||||
self.ui.warn(_("exception: %s\n") % str(e))
|
||||
|
||||
self.ui.log(
|
||||
"edenapi_error",
|
||||
exception_msg=str(e),
|
||||
exception_type=type(e).__name__,
|
||||
traceback=traceback.format_exc(),
|
||||
)
|
||||
|
||||
edenapi.logexception(self.ui, e)
|
||||
self.ui.metrics.gauge("edenapi_fallbacks", 1)
|
||||
|
||||
rcvd = 0
|
||||
@ -1043,8 +1033,6 @@ class fileserverclient(object):
|
||||
assert all(store.has(p.oid()) for p in pointers)
|
||||
|
||||
def logstacktrace(self):
|
||||
import traceback
|
||||
|
||||
self.ui.log(
|
||||
"remotefilelog",
|
||||
"excess remotefilelog fetching:\n%s\n",
|
||||
|
@ -536,8 +536,8 @@ def wraprepo(repo):
|
||||
except Exception as e:
|
||||
self.ui.warn(_("encountered error during HTTPS fetching;"))
|
||||
self.ui.warn(_(" falling back to SSH\n"))
|
||||
if edenapi.debug(self.ui):
|
||||
self.ui.warn(_("exception: %s\n") % str(e))
|
||||
edenapi.logexception(self.ui, e)
|
||||
self.ui.metrics.gauge("edenapi_fallbacks", 1)
|
||||
|
||||
start = util.timer()
|
||||
with self.ui.timesection("fetchingtrees"):
|
||||
|
@ -125,7 +125,7 @@ pub enum ApiErrorKind {
|
||||
BadResponse,
|
||||
#[fail(display = "libcurl returned an error")]
|
||||
Curl,
|
||||
#[fail(display = "Received HTTP status {} with response: {:?}", code, msg)]
|
||||
#[fail(display = "Received HTTP status '{}' with response: {:?}", code, msg)]
|
||||
Http { code: StatusCode, msg: String },
|
||||
#[fail(display = "Proxy server returned an error (HTTP {})", _0)]
|
||||
Proxy(StatusCode),
|
||||
|
Loading…
Reference in New Issue
Block a user