Skip to content

Exceptions

src.utils.exceptions.log_on_exception(logr: Any = None) -> Callable

Decorator to log any exception that occurs.

Parameters:

Name Type Description Default
logr Any

Logger object to output any exception messages.

None

Returns:

Type Description
Callable

Wrapped function.

Source code in src\utils\exceptions.py
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
def log_on_exception(logr: Any = None) -> Callable:
    """Decorator to log any exception that occurs.

    Args:
        logr: Logger object to output any exception messages.

    Returns:
        Wrapped function.
    """
    logr = logr or logger

    def decorator(func):
        def wrapper(*args, **kwargs):
            # Final exception catch
            try:
                return func(*args, **kwargs)
            except Exception as e:
                logr.log_exception(e)
                raise e
        return wrapper
    return decorator

src.utils.exceptions.return_on_exception(response: Optional[Any] = None) -> Callable

Decorator to handle any exception and return appropriate failure value.

Parameters:

Name Type Description Default
response Any | None

Value to return if an exception occurs.

None

Returns:

Type Description
Callable

Wrapped function.

Source code in src\utils\exceptions.py
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
def return_on_exception(response: Optional[Any] = None) -> Callable:
    """Decorator to handle any exception and return appropriate failure value.

    Args:
        response: Value to return if an exception occurs.

    Returns:
        Wrapped function.
    """
    def decorator(func):
        def wrapper(*args, **kwargs):
            # Final exception catch
            with suppress(Exception):
                return func(*args, **kwargs)
            return response
        return wrapper
    return decorator

src.utils.exceptions.try_photoshop(func) -> Callable

Decorator to handle trying to run a Photoshop action but allowing exceptions to fail silently.

Parameters:

Name Type Description Default
func

Function being wrapped.

required

Returns:

Type Description
Callable

The wrapped function.

Source code in src\utils\exceptions.py
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
def try_photoshop(func) -> Callable:
    """Decorator to handle trying to run a Photoshop action but allowing exceptions to fail silently.

    Args:
        func: Function being wrapped.

    Returns:
        The wrapped function.
    """
    def wrapper(self, *args, **kwargs):
        try:
            result = func(self, *args, **kwargs)
            return result
        except PS_EXCEPTIONS:
            return
    return wrapper

src.utils.exceptions.get_photoshop_error_message(err: Exception) -> str

Gets a user-facing error message based on a given Photoshop access exception.

Parameters:

Name Type Description Default
err Exception

Exception object containing the reason an action failed.

required

Returns:

Type Description
str

Proper user response for this exception.

Source code in src\utils\exceptions.py
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
def get_photoshop_error_message(err: Exception) -> str:
    """Gets a user-facing error message based on a given Photoshop access exception.

    Args:
        err: Exception object containing the reason an action failed.

    Returns:
        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"
    )

src.utils.exceptions.get_com_error(signed_int: int) -> str

Check for an error message for both the signed and unsigned version of a COMError code (HRESULT).

Parameters:

Name Type Description Default
signed_int int

Signed integer representing a COMError exception.

required

Returns:

Type Description
str

The string error message associated with this COMError code.

Source code in src\utils\exceptions.py
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
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).

    Args:
        signed_int: Signed integer representing a COMError exception.

    Returns:
        The string error message associated with this COMError code.
    """
    try:
        err = FormatMessage(signed_int)
    except Exception as e:
        try:
            unsigned_int = c_uint32(signed_int).value
            err = FormatMessage(unsigned_int) or e.args[2]
        except Exception as e:
            err = e.args[2]
    return err