Skip to content

Commit af4b605

Browse files
authored
Better CLI error messages (#4035)
* Better error messages in stack CLI * Apply to more exceptions * Fix logic * Linting
1 parent 9052ea6 commit af4b605

16 files changed

+103
-78
lines changed

src/zenml/cli/artifact.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def update_artifact(
105105
remove_tags=remove_tag,
106106
)
107107
except (KeyError, ValueError) as e:
108-
cli_utils.error(str(e))
108+
cli_utils.exception(e)
109109
else:
110110
cli_utils.declare(f"Artifact '{artifact.id}' updated.")
111111

@@ -192,7 +192,7 @@ def update_artifact_version(
192192
remove_tags=remove_tag,
193193
)
194194
except (KeyError, ValueError) as e:
195-
cli_utils.error(str(e))
195+
cli_utils.exception(e)
196196
else:
197197
cli_utils.declare(f"Artifact version '{artifact_version.id}' updated.")
198198

src/zenml/cli/authorized_device.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def describe_authorized_device(id_or_prefix: str) -> None:
4747
id_or_prefix=id_or_prefix,
4848
)
4949
except KeyError as e:
50-
cli_utils.error(str(e))
50+
cli_utils.exception(e)
5151

5252
cli_utils.print_pydantic_model(
5353
title=f"Authorized device `{device.id}`",
@@ -93,7 +93,7 @@ def lock_authorized_device(id: str) -> None:
9393
locked=True,
9494
)
9595
except KeyError as e:
96-
cli_utils.error(str(e))
96+
cli_utils.exception(e)
9797
else:
9898
cli_utils.declare(f"Locked authorized device `{id}`.")
9999

@@ -112,7 +112,7 @@ def unlock_authorized_device(id: str) -> None:
112112
locked=False,
113113
)
114114
except KeyError as e:
115-
cli_utils.error(str(e))
115+
cli_utils.exception(e)
116116
else:
117117
cli_utils.declare(f"Locked authorized device `{id}`.")
118118

@@ -143,6 +143,6 @@ def delete_authorized_device(id: str, yes: bool = False) -> None:
143143
try:
144144
Client().delete_authorized_device(id_or_prefix=id)
145145
except KeyError as e:
146-
cli_utils.error(str(e))
146+
cli_utils.exception(e)
147147
else:
148148
cli_utils.declare(f"Deleted authorized device `{id}`.")

src/zenml/cli/code_repository.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def describe_code_repository(name_id_or_prefix: str) -> None:
180180
name_id_or_prefix=name_id_or_prefix,
181181
)
182182
except KeyError as err:
183-
cli_utils.error(str(err))
183+
cli_utils.exception(err)
184184
else:
185185
cli_utils.print_pydantic_model(
186186
title=f"Code repository '{code_repository.name}'",
@@ -303,6 +303,6 @@ def delete_code_repository(name_or_id: str, yes: bool = False) -> None:
303303
try:
304304
Client().delete_code_repository(name_id_or_prefix=name_or_id)
305305
except KeyError as e:
306-
cli_utils.error(str(e))
306+
cli_utils.exception(e)
307307
else:
308308
cli_utils.declare(f"Deleted code repository `{name_or_id}`.")

src/zenml/cli/deployment.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def list_deployments(**kwargs: Any) -> None:
8383
with console.status("Listing deployments...\n"):
8484
deployments = client.list_deployments(**kwargs)
8585
except KeyError as err:
86-
cli_utils.error(str(err))
86+
cli_utils.exception(err)
8787
else:
8888
if not deployments.items:
8989
cli_utils.declare("No deployments found for this filter.")
@@ -140,7 +140,7 @@ def describe_deployment(
140140
name_id_or_prefix=deployment_name_or_id,
141141
)
142142
except KeyError as e:
143-
cli_utils.error(str(e))
143+
cli_utils.exception(e)
144144
else:
145145
cli_utils.pretty_print_deployment(
146146
deployment,
@@ -245,7 +245,7 @@ def provision_deployment(
245245
timeout=timeout,
246246
)
247247
except KeyError as e:
248-
cli_utils.error(str(e))
248+
cli_utils.exception(e)
249249
else:
250250
cli_utils.declare(
251251
f"Provisioned deployment '{deployment_name_or_id}'."
@@ -580,7 +580,7 @@ def refresh_deployment(
580580
)
581581

582582
except KeyError as e:
583-
cli_utils.error(str(e))
583+
cli_utils.exception(e)
584584
else:
585585
cli_utils.pretty_print_deployment(deployment, show_secret=True)
586586

@@ -694,7 +694,7 @@ def log_deployment(
694694
tail=tail,
695695
)
696696
except KeyError as e:
697-
cli_utils.error(str(e))
697+
cli_utils.exception(e)
698698
else:
699699
for log in logs:
700700
print(log)

src/zenml/cli/integration.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
confirmation,
2727
declare,
2828
error,
29+
exception,
2930
format_integration_list,
3031
install_packages,
3132
print_table,
@@ -89,7 +90,7 @@ def get_requirements(integration_name: Optional[str] = None) -> None:
8990
integration_name
9091
)
9192
except KeyError as e:
92-
error(str(e))
93+
exception(e)
9394
else:
9495
if requirements:
9596
title(

src/zenml/cli/model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def register_model(
212212
)
213213
)
214214
except (EntityExistsError, ValueError) as e:
215-
cli_utils.error(str(e))
215+
cli_utils.exception(e)
216216

217217
cli_utils.print_table([_model_to_print(model)])
218218

@@ -380,7 +380,7 @@ def delete_model(
380380
model_name_or_id=model_name_or_id,
381381
)
382382
except (KeyError, ValueError) as e:
383-
cli_utils.error(str(e))
383+
cli_utils.exception(e)
384384
else:
385385
cli_utils.declare(f"Model '{model_name_or_id}' deleted.")
386386

@@ -558,7 +558,7 @@ def delete_model_version(
558558
model_version_id=model_version.id,
559559
)
560560
except (KeyError, ValueError) as e:
561-
cli_utils.error(str(e))
561+
cli_utils.exception(e)
562562
else:
563563
cli_utils.declare(
564564
f"Model version '{model_version_name_or_number_or_id}' deleted from model '{model_name_or_id}'."

src/zenml/cli/pipeline.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ def delete_pipeline(
621621
name_id_or_prefix=pipeline_name_or_id,
622622
)
623623
except KeyError as e:
624-
cli_utils.error(str(e))
624+
cli_utils.exception(e)
625625
else:
626626
cli_utils.declare(f"Deleted pipeline `{pipeline_name_or_id}`.")
627627

@@ -681,7 +681,7 @@ def update_schedule(
681681
cron_expression=cron_expression,
682682
)
683683
except Exception as e:
684-
cli_utils.error(str(e))
684+
cli_utils.exception(e)
685685
else:
686686
cli_utils.declare(f"Updated schedule '{schedule_name_or_id}'.")
687687

@@ -713,7 +713,7 @@ def delete_schedule(schedule_name_or_id: str, yes: bool = False) -> None:
713713
try:
714714
Client().delete_schedule(name_id_or_prefix=schedule_name_or_id)
715715
except KeyError as e:
716-
cli_utils.error(str(e))
716+
cli_utils.exception(e)
717717
else:
718718
cli_utils.declare(f"Deleted schedule '{schedule_name_or_id}'.")
719719

@@ -736,7 +736,7 @@ def list_pipeline_runs(**kwargs: Any) -> None:
736736
with console.status("Listing pipeline runs...\n"):
737737
pipeline_runs = client.list_pipeline_runs(**kwargs)
738738
except KeyError as err:
739-
cli_utils.error(str(err))
739+
cli_utils.exception(err)
740740
else:
741741
if not pipeline_runs.items:
742742
cli_utils.declare("No pipeline runs found for this filter.")
@@ -832,7 +832,7 @@ def delete_pipeline_run(
832832
name_id_or_prefix=run_name_or_id,
833833
)
834834
except KeyError as e:
835-
cli_utils.error(str(e))
835+
cli_utils.exception(e)
836836
else:
837837
cli_utils.declare(f"Deleted pipeline run '{run_name_or_id}'.")
838838

@@ -862,7 +862,7 @@ def refresh_pipeline_run(
862862
)
863863

864864
except KeyError as e:
865-
cli_utils.error(str(e))
865+
cli_utils.exception(e)
866866
else:
867867
cli_utils.declare(
868868
f"Refreshed the status of pipeline run '{run.name}'."
@@ -887,7 +887,7 @@ def list_pipeline_builds(**kwargs: Any) -> None:
887887
with console.status("Listing pipeline builds...\n"):
888888
pipeline_builds = client.list_builds(hydrate=True, **kwargs)
889889
except KeyError as err:
890-
cli_utils.error(str(err))
890+
cli_utils.exception(err)
891891
else:
892892
if not pipeline_builds.items:
893893
cli_utils.declare("No pipeline builds found for this filter.")
@@ -935,7 +935,7 @@ def delete_pipeline_build(
935935
try:
936936
Client().delete_build(build_id)
937937
except KeyError as e:
938-
cli_utils.error(str(e))
938+
cli_utils.exception(e)
939939
else:
940940
cli_utils.declare(f"Deleted pipeline build '{build_id}'.")
941941

@@ -1224,7 +1224,7 @@ def deploy_snapshot(
12241224
timeout=timeout,
12251225
)
12261226
except KeyError as e:
1227-
cli_utils.error(str(e))
1227+
cli_utils.exception(e)
12281228
else:
12291229
cli_utils.declare(
12301230
f"Provisioned deployment '{deployment_name_or_id}'."
@@ -1245,7 +1245,7 @@ def list_pipeline_snapshots(**kwargs: Any) -> None:
12451245
with console.status("Listing pipeline snapshots...\n"):
12461246
pipeline_snapshots = client.list_snapshots(hydrate=True, **kwargs)
12471247
except KeyError as err:
1248-
cli_utils.error(str(err))
1248+
cli_utils.exception(err)
12491249
else:
12501250
if not pipeline_snapshots.items:
12511251
cli_utils.declare("No pipeline snapshots found for this filter.")

src/zenml/cli/project.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def register_project(
111111
)
112112
cli_utils.success("✔ Project created successfully.")
113113
except Exception as e:
114-
cli_utils.error(str(e))
114+
cli_utils.exception(e)
115115

116116
if set_project:
117117
client.set_active_project(project_name)
@@ -153,7 +153,7 @@ def set_project(project_name_or_id: str, default: bool = False) -> None:
153153
f"✔ The active project has been set to {project_name_or_id}"
154154
)
155155
except Exception as e:
156-
cli_utils.error(str(e))
156+
cli_utils.exception(e)
157157

158158
if default:
159159
client.update_user(
@@ -184,7 +184,7 @@ def describe_project(project_name_or_id: Optional[str] = None) -> None:
184184
try:
185185
project_ = client.get_project(project_name_or_id)
186186
except KeyError as err:
187-
cli_utils.error(str(err))
187+
cli_utils.exception(err)
188188
else:
189189
cli_utils.print_pydantic_models(
190190
[project_], exclude_columns=["created", "updated"]
@@ -208,4 +208,4 @@ def delete_project(project_name_or_id: str) -> None:
208208
f"Project '{project_name_or_id}' deleted successfully."
209209
)
210210
except Exception as e:
211-
cli_utils.error(str(e))
211+
cli_utils.exception(e)

src/zenml/cli/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,4 +780,4 @@ def show(local: bool = False, ngrok_token: Optional[str] = None) -> None:
780780
try:
781781
zenml.show(ngrok_token=ngrok_token)
782782
except RuntimeError as e:
783-
cli_utils.error(str(e))
783+
cli_utils.exception(e)

src/zenml/cli/service_accounts.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def _create_api_key(
5858
description=description or "",
5959
)
6060
except (KeyError, EntityExistsError) as e:
61-
cli_utils.error(str(e))
61+
cli_utils.exception(e)
6262

6363
cli_utils.declare(f"Successfully created API key `{name}`.")
6464

@@ -150,7 +150,7 @@ def create_service_account(
150150

151151
cli_utils.declare(f"Created service account '{service_account.name}'.")
152152
except EntityExistsError as err:
153-
cli_utils.error(str(err))
153+
cli_utils.exception(err)
154154

155155
if create_api_key:
156156
_create_api_key(
@@ -176,7 +176,7 @@ def describe_service_account(service_account_name_or_id: str) -> None:
176176
service_account_name_or_id
177177
)
178178
except KeyError as err:
179-
cli_utils.error(str(err))
179+
cli_utils.exception(err)
180180
else:
181181
cli_utils.print_pydantic_model(
182182
title=f"Service account '{service_account.name}'",
@@ -261,7 +261,7 @@ def update_service_account(
261261
active=active,
262262
)
263263
except (KeyError, EntityExistsError) as err:
264-
cli_utils.error(str(err))
264+
cli_utils.exception(err)
265265

266266

267267
@service_account.command("delete")
@@ -276,7 +276,7 @@ def delete_service_account(service_account_name_or_id: str) -> None:
276276
try:
277277
client.delete_service_account(service_account_name_or_id)
278278
except (KeyError, IllegalOperationError) as err:
279-
cli_utils.error(str(err))
279+
cli_utils.exception(err)
280280

281281
cli_utils.declare(
282282
f"Deleted service account '{service_account_name_or_id}'."
@@ -370,7 +370,7 @@ def describe_api_key(service_account_name_or_id: str, name_or_id: str) -> None:
370370
name_id_or_prefix=name_or_id,
371371
)
372372
except KeyError as e:
373-
cli_utils.error(str(e))
373+
cli_utils.exception(e)
374374

375375
cli_utils.print_pydantic_model(
376376
title=f"API key '{api_key.name}'",
@@ -399,7 +399,7 @@ def list_api_keys(service_account_name_or_id: str, /, **kwargs: Any) -> None:
399399
**kwargs,
400400
)
401401
except KeyError as e:
402-
cli_utils.error(str(e))
402+
cli_utils.exception(e)
403403

404404
if not api_keys.items:
405405
cli_utils.declare("No API keys found for this filter.")
@@ -455,7 +455,7 @@ def update_api_key(
455455
active=active,
456456
)
457457
except (KeyError, EntityExistsError) as e:
458-
cli_utils.error(str(e))
458+
cli_utils.exception(e)
459459

460460
cli_utils.declare(f"Successfully updated API key `{name_or_id}`.")
461461

@@ -510,7 +510,7 @@ def rotate_api_key(
510510
retain_period_minutes=retain,
511511
)
512512
except KeyError as e:
513-
cli_utils.error(str(e))
513+
cli_utils.exception(e)
514514

515515
cli_utils.declare(f"Successfully rotated API key `{name_or_id}`.")
516516
if retain:
@@ -581,6 +581,6 @@ def delete_api_key(
581581
name_id_or_prefix=name_or_id,
582582
)
583583
except KeyError as e:
584-
cli_utils.error(str(e))
584+
cli_utils.exception(e)
585585
else:
586586
cli_utils.declare(f"Deleted API key `{name_or_id}`.")

0 commit comments

Comments
 (0)