Skip to content

Commit 740cb83

Browse files
authored
Log instructions when azure credentials missing (#26)
1 parent c401b53 commit 740cb83

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/prompt_passage/auth_providers.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22

33
from abc import ABC, abstractmethod
44

5-
from azure.identity import DefaultAzureCredential
5+
import logging
6+
7+
from azure.identity import (
8+
DefaultAzureCredential,
9+
CredentialUnavailableError,
10+
)
611
from azure.core.credentials import AccessToken
12+
from azure.core.exceptions import ClientAuthenticationError
713

814

915
class TokenProvider(ABC):
@@ -35,5 +41,12 @@ def __init__(self) -> None:
3541
self._credential = DefaultAzureCredential()
3642

3743
def get_token(self) -> str:
38-
access_token: AccessToken = self._credential.get_token(self._SCOPE)
44+
try:
45+
access_token: AccessToken = self._credential.get_token(self._SCOPE)
46+
except (CredentialUnavailableError, ClientAuthenticationError):
47+
logging.error("=" * 60)
48+
logging.error("Azure credentials required. Please run 'az login'.")
49+
logging.error("=" * 60)
50+
raise
51+
3952
return access_token.token

0 commit comments

Comments
 (0)