modal.exception

modal.exception.AuthError

class AuthError(modal.exception.Error)

Raised when a client has missing or invalid authentication.

modal.exception.ConnectionError

class ConnectionError(modal.exception.Error)

Raised when an issue occurs while connecting to the Modal servers.

modal.exception.DeprecationError

class DeprecationError(UserWarning)

UserWarning category emitted when a deprecated Modal feature or API is used.

modal.exception.ExecutionError

class ExecutionError(modal.exception.Error)

Raised when something unexpected happened during runtime.

modal.exception.FunctionTimeoutError

class FunctionTimeoutError(modal.exception.TimeoutError)

Raised when a Function exceeds its execution duration limit and times out.

modal.exception.InputCancellation

class InputCancellation(BaseException)

Raised when the current input is cancelled by the task

Intentionally a BaseException instead of an Exception, so it won’t get caught by unspecified user exception clauses that might be used for retries and other control flow.

modal.exception.InteractiveTimeoutError

class InteractiveTimeoutError(modal.exception.TimeoutError)

Raised when interactive frontends time out while trying to connect to a container.

modal.exception.InvalidError

class InvalidError(modal.exception.Error)

Raised when user does something invalid.

modal.exception.ModuleNotMountable

class ModuleNotMountable(Exception)

modal.exception.MountUploadTimeoutError

class MountUploadTimeoutError(modal.exception.TimeoutError)

Raised when a Mount upload times out.

modal.exception.NotFoundError

class NotFoundError(modal.exception.Error)

Raised when a requested resource was not found.

modal.exception.PendingDeprecationError

class PendingDeprecationError(UserWarning)

Soon to be deprecated feature. Only used intermittently because of multi-repo concerns.

modal.exception.RemoteError

class RemoteError(modal.exception.Error)

Raised when an error occurs on the Modal server.

modal.exception.SandboxTerminatedError

class SandboxTerminatedError(modal.exception.Error)

Raised when a Sandbox is terminated for an internal reason.

modal.exception.SandboxTimeoutError

class SandboxTimeoutError(modal.exception.TimeoutError)

Raised when a Sandbox exceeds its execution duration limit and times out.

modal.exception.TimeoutError

class TimeoutError(modal.exception.Error)

Base class for Modal timeouts.

modal.exception.VersionError

class VersionError(modal.exception.Error)

Raised when the current client version of Modal is unsupported.

modal.exception.VolumeUploadTimeoutError

class VolumeUploadTimeoutError(modal.exception.TimeoutError)

Raised when a Volume upload times out.

modal.exception.deprecation_error

def deprecation_error(deprecated_on: Tuple[int, int, int], msg: str):

modal.exception.deprecation_warning

def deprecation_warning(
    deprecated_on: Tuple[int, int, int], msg: str, *, pending: bool = False, show_source: bool = True
) -> None:

Utility for getting the proper stack entry.

See the implementation of the built-in warnings.warn.

modal.exception.simulate_preemption

def simulate_preemption(wait_seconds: int, jitter_seconds: int = 0):

Utility for simulating a preemption interrupt after wait_seconds seconds. The first interrupt is the SIGINT signal. After 30 seconds, a second interrupt will trigger.

This second interrupt simulates SIGKILL, and should not be caught. Optionally add between zero and jitter_seconds seconds of additional waiting before first interrupt.

Usage:

import time
from modal.exception import simulate_preemption

simulate_preemption(3)

try:
    time.sleep(4)
except KeyboardInterrupt:
    print("got preempted") # Handle interrupt
    raise

See https://modal.com/docs/guide/preemption for more details on preemption handling.