Skip to content

Commit

Permalink
exp push/remove: show message on failure when notifying to Studio (it…
Browse files Browse the repository at this point in the history
  • Loading branch information
skshetry authored Mar 28, 2023
1 parent 1bc4c1d commit 006b6f3
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions dvc/utils/studio.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple
from urllib.parse import urljoin

import requests
from dvc_studio_client.post_live_metrics import get_studio_repo_url
from funcy import compact
from requests import RequestException, Session
from requests.adapters import HTTPAdapter

if TYPE_CHECKING:
Expand Down Expand Up @@ -37,7 +37,7 @@ def post(
timeout: int = 5,
) -> "Response":
endpoint = urljoin(url or STUDIO_URL, endpoint)
session = Session()
session = requests.Session()
session.mount(endpoint, HTTPAdapter(max_retries=max_retries))

logger.trace("Sending %s to %s", data, endpoint) # type: ignore[attr-defined]
Expand Down Expand Up @@ -87,7 +87,21 @@ def notify_refs(

try:
post("/webhook/dvc", token=token, data=data, url=studio_url)
except RequestException:
# TODO: handle expected failures and show appropriate message
# TODO: handle unexpected failures and show appropriate message
logger.debug("failed to notify Studio", exc_info=True)
except requests.RequestException as e:
logger.debug("", exc_info=True)

msg = str(e)
if (r := e.response) is not None:
status = r.status_code
# try to parse json response for more detailed error message
try:
d = r.json()
logger.trace( # type: ignore[attr-defined]
"received response: %s (status=%r)", d, status
)
except requests.JSONDecodeError:
pass
else:
if detail := d.get("detail"):
msg = f"{detail} ({status=})"
logger.warning("failed to notify Studio: %s", msg.lower())

0 comments on commit 006b6f3

Please sign in to comment.