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:
Arun Kulshreshtha 2019-06-28 15:02:56 -07:00 committed by Facebook Github Bot
parent 367a4a7cea
commit 2bd15eca26
5 changed files with 23 additions and 27 deletions

View File

@ -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

View File

@ -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")

View File

@ -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",

View File

@ -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"):

View File

@ -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),