Errors
Every exception pydantic_monty raises, plus the traceback Frame they carry and the ExcType names accepted when
answering a snapshot with an exception.
Bases: Exception
Base exception for all Monty interpreter errors.
Catching MontyError will catch syntax, runtime, and typing errors from Monty.
This exception is raised internally by Monty and cannot be constructed directly.
def exception() -> BaseException
Returns the inner exception as a Python exception object.
def __str__() -> str
Returns the exception message.
Bases: MontyError
Raised when Python code has syntax errors or cannot be parsed by Monty.
Inherits exception(), str() from MontyError.
def traceback() -> list[Frame]
Returns the Monty traceback as a list of Frame objects.
def display(format: Literal['traceback', 'type-msg', 'msg'] = 'traceback') -> str
Returns formatted exception string.
format : Literal[‘traceback’, ‘type-msg’, ‘msg’] Default: 'traceback'
‘traceback’ - full traceback with exception ‘type-msg’ - ‘ExceptionType: message’ format ‘msg’ - just the message
Bases: MontyError
Raised when type checking rejects a fed snippet.
Type checking runs inside the worker subprocess; the diagnostics arrive
pre-rendered as text, in the type_check_format chosen at checkout.
Inherits exception(), str() from MontyError. Cannot be constructed directly from Python.
def display() -> str
Returns the rendered type-check diagnostics.
Bases: MontyError
Raised when Monty code fails during execution.
Inherits exception(), str() from MontyError. Additionally provides traceback() and display() methods.
def traceback() -> list[Frame]
Returns the Monty traceback as a list of Frame objects.
def display(format: Literal['traceback', 'type-msg', 'msg'] = 'traceback') -> str
Returns formatted exception string.
format : Literal[‘traceback’, ‘type-msg’, ‘msg’] Default: 'traceback'
‘traceback’ - full traceback with exception ‘type-msg’ - ‘ExceptionType: message’ format ‘msg’ - just the message
Bases: MontyError
Raised when a host value cannot be converted across the Monty/host boundary.
A value Monty cannot represent — an external_lookup entry or an inputs
value of an unsupported type — rejects the feed with this error rather than
crossing into the sandbox. Inherits exception() (a native TypeError) and
__str__() (the conversion message) from MontyError.
Bases: MontyError
Raised when the sandbox is gone and the session with it.
This is the failure mode subprocess pools exist to contain: the worker is
gone — segfault, allocator abort, external kill, request_timeout
watchdog, or a fatal error it announced before exiting — but the host
process is unharmed and the pool replaces it. A remote server also reports
its own failure to start a worker this way. Catch this error to retry or
report; the message says which happened.
exit_status is None whenever the process could not be reaped, which
includes every remote worker.
Cannot be constructed directly from Python.
True when the pool’s request_timeout watchdog killed the worker.
Type: bool
Exit code of the dead worker when the OS reported one (signal deaths report None).
Bases: MontyError
Raised when a remote worker’s connection closed mid-session (WebSocket transport only).
The local analogue is MontyCrashedError. The sandbox may have died, or
the server may have dropped the session by policy — an idle, session, or
turn timeout, or being over capacity. A client that only sees the
connection go away cannot tell those apart, so this error claims no more
than that. Retry on a fresh session.
Cannot be constructed directly from Python.
Bases: MontyError
Raised when the remote server is shutting down (WebSocket transport only).
Not an error in your code, which is why it is the one exception here
without an Error suffix; it still subclasses MontyError. The request
that raised it did not run, so re-running it on a fresh session is
safe.
dump carries the session state captured just before shutdown — restore
it on a new session to carry the session across a server restart, with
session.load_session (idle, between feeds) or session.load_snapshot
(suspended mid-feed).
One caveat: if the interrupted request was answering a suspension (an
external function or os callback), the host already ran that call and
the restored session re-announces it, so it runs again. Make such
callbacks idempotent if you intend to restore across a shutdown.
Cannot be constructed directly from Python.
Restorable session dump, or None when nothing had run yet or the server’s dump failed.
A single frame in a Monty traceback.
The filename where the code is located.
Type: str
Line number (1-based).
Type: int
Column number (1-based).
Type: int
End line number (1-based).
Type: int
End column number (1-based).
Type: int
The name of the function, or None for module-level code.
The source code line for preview in the traceback.
def dict() -> dict[str, int | str | None]
dict of attributes.
String names of Python exception types that Monty understands.
Used by ExternalExceptionData to identify an exception by name rather than
passing a concrete Python exception instance. Names match Python’s built-in
exception classes, except for json.JSONDecodeError, re.PatternError and
binascii.Error, which are dotted to disambiguate from their ValueError /
Exception parents.
Default: Literal['Exception', 'BaseException', 'SystemExit', 'KeyboardInterrupt', 'ArithmeticError', 'OverflowError', 'ZeroDivisionError', 'LookupError', 'IndexError', 'KeyError', 'RuntimeError', 'NotImplementedError', 'RecursionError', 'AttributeError', 'FrozenInstanceError', 'NameError', 'UnboundLocalError', 'ValueError', 'UnicodeDecodeError', 'UnicodeEncodeError', 'json.JSONDecodeError', 'ImportError', 'ModuleNotFoundError', 'OSError', 'FileNotFoundError', 'FileExistsError', 'IsADirectoryError', 'NotADirectoryError', 'PermissionError', 'io.UnsupportedOperation', 'AssertionError', 'MemoryError', 'StopIteration', 'SyntaxError', 'TimeoutError', 'TypeError', 're.PatternError', 'binascii.Error']