Skip to content

Exceptions

EXCEPTION UTILITIES

PS_ERROR_CODES: dict[int:str] = {-2147417846: 'Photoshop is currently busy, close any dialog boxes and stop any pending actions.', -2147023170: 'Unable to make connection with Photoshop, please check the FAQ for solutions.', -2147352565: "Failed to load a PSD template or other file, ensure template file isn't corrupted and that you have allocated enough scratch disk space and RAM to Photoshop.", -2147352567: 'Photoshop does not appear to be installed. If Photoshop is installed, check the FAQ for solutions.', -2147220261: 'Invalid data type passed to action descriptor function.', -2147213497: 'Tried to transform, select, or translate an empty layer.', -2147212704: 'Action descriptor or layer object key/property is missing.', -2147220262: "Photoshop tried to load a PSD template or file that doesn't exist.", -2147220279: 'Wrong type of value passed to a Photoshop object property.', -2147213327: 'Tried to interact with a text layer that is rasterized or has an uninstalled font.', -2147213404: "Tried to delete a layer that doesn't exist."} module-attribute

EXCEPTION CLASSES

ScryfallError

Bases: Exception

Exception representing a failure to retrieve Scryfall data.

Source code in src/utils/exceptions.py
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
class ScryfallError(Exception):
    """Exception representing a failure to retrieve Scryfall data."""

    def __init__(
        self,
        url: Optional[str] = None,
        name: Optional[str] = '',
        code: Optional[str] = '',
        number: Optional[str] = '',
        lang: Optional[str] = '',

    ):
        # Establish string patterns
        name = f"{name} " if name else ''
        code = f"[{code}] " if code else ''
        number = f"{{{number}}} " if number else ''
        lang = f"<{lang}>" if lang else ''

        # Pass the correct message
        super().__init__(
            f"Scryfall request failed"
        ) if not any([url, name, code, number, lang]) else (
            f"Couldn't find card: {name}{code}{number}{lang}\n"
            f"Scryfall: {url or 'Request Rejected'}"
        )

get_com_error(signed_int)

Check for an error message for both the signed and unsigned version of a COMError code (HRESULT). @param signed_int: Signed integer representing a COMError exception. @return: The string error message associated with this COMError code.

Source code in src/utils/exceptions.py
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
def get_com_error(signed_int: int) -> str:
    """
    Check for an error message for both the signed and unsigned version of a COMError code (HRESULT).
    @param signed_int: Signed integer representing a COMError exception.
    @return: The string error message associated with this COMError code.
    """
    try:
        err = FormatMessage(signed_int)
    except BaseException as e:
        try:
            unsigned_int = c_uint32(signed_int).value
            err = FormatMessage(unsigned_int)
        except BaseException as e:
            err = e.args[2]
    return err

get_photoshop_error_message(err)

Gets a user-facing error message based on a given Photoshop access exception. @param err: Exception object containing the reason an action failed. @return: Proper user response for this exception.

Source code in src/utils/exceptions.py
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
def get_photoshop_error_message(err: Exception) -> str:
    """
    Gets a user-facing error message based on a given Photoshop access exception.
    @param err: Exception object containing the reason an action failed.
    @return: Proper user response for this exception.
    """
    return (
        "Photoshop is currently busy, close any dialogs and stop any actions.\n"
    ) if 'busy' in str(err).lower() else (
        "Photoshop does not appear to be installed on your system.\n"
        "Please close Proxyshop and install a fresh copy of Photoshop,\n"
        "if Photoshop is installed, view the FAQ for troubleshooting.\n"
    )