Skip to content

Commit abc5932

Browse files
authored
Merge pull request #798 from mlco2/fix/cli-improvements
fix: improve cli error-handling
2 parents 29b1175 + fac0126 commit abc5932

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

codecarbon/cli/main.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def show_config(path: Path = Path("./.codecarbon.config")) -> None:
9696
print(org)
9797
except Exception as e:
9898
raise ValueError(
99-
f"Your configuration is invalid, please run `codecarbon config --init` first! (error: {e})"
99+
f"Your configuration is invalid, please verify your configuration file at {path}. To start from scratch, run `codecarbon config` and overwrite your configuration file. (error: {e})"
100100
)
101101

102102

@@ -107,9 +107,14 @@ def get_fief_auth():
107107

108108

109109
def _get_access_token():
110-
access_token_info = get_fief_auth().access_token_info()
111-
access_token = access_token_info["access_token"]
112-
return access_token
110+
try:
111+
access_token_info = get_fief_auth().access_token_info()
112+
access_token = access_token_info["access_token"]
113+
return access_token
114+
except Exception as e:
115+
raise ValueError(
116+
f"Not able to retrieve the access token, please run `codecarbon login` first! (error: {e})"
117+
)
113118

114119

115120
def _get_id_token():
@@ -223,6 +228,9 @@ def config():
223228
description=org_description,
224229
)
225230
organization = api.create_organization(organization=organization_create)
231+
if organization is None:
232+
print("Error creating organization")
233+
return
226234
print(f"Created organization : {organization}")
227235
else:
228236
organization = [orga for orga in organizations if orga["name"] == org][0]

codecarbon/core/api_client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ def __init__(
7070
def _get_headers(self):
7171
headers = {"Content-Type": "application/json"}
7272
if self.api_key:
73-
print(type(self.api_key))
7473
# set the x-api-token header
7574
headers["x-api-token"] = self.api_key
7675
elif self.access_token:

0 commit comments

Comments
 (0)