Skip to content

Commit 3cfb43f

Browse files
committed
🥅 Added better exception handling for unrecognised artifact
1 parent dd3e584 commit 3cfb43f

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

‎simvue/client.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -478,11 +478,13 @@ def list_artifacts(
478478

479479
def _retrieve_artifacts_from_server(
480480
self, run_id: str, name: str
481-
) -> typing.Generator[tuple[str, Artifact], None, None]:
481+
) -> FileArtifact | ObjectArtifact | None:
482482
return Artifact.from_name(
483483
run_id=run_id,
484484
name=name,
485-
) # type: ignore
485+
server_url=self._user_config.server.url,
486+
server_token=self._user_config.server.token,
487+
)
486488

487489
@prettify_pydantic
488490
@pydantic.validate_call
@@ -530,12 +532,14 @@ def get_artifact(
530532
RuntimeError
531533
if retrieval of artifact from the server failed
532534
"""
533-
_artifact = Artifact.from_name(
534-
run_id=run_id,
535-
name=name,
536-
server_url=self._user_config.server.url,
537-
server_token=self._user_config.server.token,
538-
)
535+
_artifact = self._retrieve_artifacts_from_server(run_id, name)
536+
537+
if not _artifact:
538+
raise ObjectNotFoundError(
539+
obj_type="artifact",
540+
name=name,
541+
extra=f"for run '{run_id}'",
542+
)
539543

540544
_content = b"".join(_artifact.download_content())
541545

@@ -577,6 +581,13 @@ def get_artifact_as_file(
577581
"""
578582
_artifact = self._retrieve_artifacts_from_server(run_id, name)
579583

584+
if not _artifact:
585+
raise ObjectNotFoundError(
586+
obj_type="artifact",
587+
name=name,
588+
extra=f"for run '{run_id}'",
589+
)
590+
580591
_download_artifact_to_file(_artifact, output_dir)
581592

582593
@prettify_pydantic

0 commit comments

Comments
 (0)