File size: 2,333 Bytes
9c6594c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""Artifact exceptions."""

from __future__ import annotations

from typing import TYPE_CHECKING, TypeVar

from wandb import errors

if TYPE_CHECKING:
    from wandb.sdk.artifacts.artifact import Artifact

    ArtifactT = TypeVar("ArtifactT", bound=Artifact)


class ArtifactStatusError(AttributeError):
    """Raised when an artifact is in an invalid state for the requested operation."""

    def __init__(
        self,
        msg: str = "Artifact is in an invalid state for the requested operation.",
        name: str | None = None,
        obj: ArtifactT | None = None,
    ):
        # Follow the same pattern as AttributeError in python 3.10+ by `name/obj` attributes
        # See: https://docs.python.org/3/library/exceptions.html#AttributeError
        try:
            super().__init__(msg, name=name, obj=obj)
        except TypeError:
            # The `name`/`obj` keyword args and attributes were only added in python >= 3.10
            super().__init__(msg)
            self.name = name or ""
            self.obj = obj


class ArtifactNotLoggedError(ArtifactStatusError):
    """Raised for Artifact methods or attributes only available after logging."""

    def __init__(self, fullname: str, obj: ArtifactT):
        *_, name = fullname.split(".")
        msg = (
            f"{fullname!r} used prior to logging artifact or while in offline mode. "
            f"Call {type(obj).wait.__qualname__}() before accessing logged artifact properties."
        )
        super().__init__(msg=msg, name=name, obj=obj)


class ArtifactFinalizedError(ArtifactStatusError):
    """Raised for Artifact methods or attributes that can't be changed after logging."""

    def __init__(self, fullname: str, obj: ArtifactT):
        *_, name = fullname.split(".")
        msg = f"{fullname!r} used on logged artifact. Can't modify finalized artifact."
        super().__init__(msg=msg, name=name, obj=obj)


class WaitTimeoutError(errors.Error):
    """Raised when wait() timeout occurs before process is finished."""


class TooFewItemsError(ValueError):
    """Raised when there are fewer items than expected in a collection.

    Intended for internal use only.
    """


class TooManyItemsError(ValueError):
    """Raised when there are more items than expected in a collection.

    Intended for internal use only.
    """