analytics: ignore request.post errors (#3292)

Users have been complaining about dvc analytics errors when they are not
connected to the internet.
This commit is contained in:
Ruslan Kuprieiev
2020-02-10 01:41:42 +02:00
committed by GitHub
parent 2786a4e59b
commit d305803015
2 changed files with 11 additions and 5 deletions
+4 -1
View File
@@ -76,7 +76,10 @@ def send(report):
headers = {"content-type": "application/json"}
with open(report, "rb") as fobj:
requests.post(url, data=fobj, headers=headers, timeout=5)
try:
requests.post(url, data=fobj, headers=headers, timeout=5)
except requests.exceptions.RequestException:
logger.debug("failed to send analytics report", exc_info=True)
os.remove(report)
+7 -4
View File
@@ -61,16 +61,19 @@ def test_runtime_info(tmp_global_config):
@mock.patch("requests.post")
def test_send(mock_post, tmp_path):
import requests
url = "https://analytics.dvc.org"
report = {"name": "dummy report"}
fname = str(tmp_path / "report")
report_file = tmp_path / "report"
with open(fname, "w") as fobj:
json.dump(report, fobj)
report_file.write_text(json.dumps(report))
mock_post.side_effect = requests.exceptions.RequestException
analytics.send(fname)
analytics.send(str(report_file))
assert mock_post.called
assert mock_post.call_args.args[0] == url
assert not report_file.exists()
@pytest.mark.parametrize(