Skip to main content
Modal-specific exception types.

Base exception

Base class for all Modal errors. Usage:
import modal

try:
    ...
except modal.Error:
    # Catch any exception raised by Modal's systems
    print("Responding to error...")

Client errors

Raised when user does something invalid. Raised when a client has missing or invalid authentication. Raised when a requested resource was not found. Raised when a resource creation conflicts with an existing resource. Raised when a user does not have permission to perform the requested operation. Raised when a resource conflict occurs between the request and current system state. Inherits from InvalidError.

Server errors

Raised when an internal error occurs in the Modal system. Raised when an error occurs in basic client/server communication. Raised when an error occurs on the Modal server. Raised when data is lost or corrupted. Raised when a server-side resource has been exhausted, e.g. a quota or rate limit. Raised when a requested operation is not implemented or not supported.

Timeout errors

Base class for Modal timeouts. Raised when a Function exceeds its execution duration limit and times out. Inherits from TimeoutError. Raised when a Sandbox exceeds its execution duration limit and times out. Inherits from TimeoutError. Raised when a container process exceeds its execution duration limit and times out. Inherits from TimeoutError. Raised when interactive frontends time out while trying to connect to a container. Inherits from TimeoutError. Raised when the Output exceeds expiration and times out. Inherits from TimeoutError. Raised when a Mount upload times out. Inherits from TimeoutError. Raised when a Volume upload times out. Inherits from TimeoutError.

Runtime errors

Raised when something unexpected happened during runtime. Raised when a Sandbox is terminated for an internal reason.

Connection errors

Raised when an issue occurs while connecting to the Modal servers. Raised when the current client version of Modal is unsupported. Raised when operations are attempted on a closed client.

Serialization errors

Raised to provide more context when an error is encountered during serialization. Raised to provide more context when an error is encountered during deserialization. Raised when an operation produces a gRPC request that is rejected by the server for being too large.

Warnings

UserWarning category emitted when a deprecated Modal feature or API is used. Warning for soon to be deprecated features. Warning originating from the Modal server and re-issued in client code. Warning emitted when a blocking Modal interface is used in an async context.

Utility functions

modal.exception.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 (simulating SIGKILL).
wait_seconds
int
required
Seconds to wait before first interrupt.
jitter_seconds
int
default:"0"
Additional random jitter (0 to jitter_seconds) before first interrupt.
Example:
import time
from modal.exception import simulate_preemption

simulate_preemption(3)

try:
    time.sleep(10)
except KeyboardInterrupt:
    print("Simulated preemption!")
    # Cleanup code here

Build docs developers (and LLMs) love