Mojo · Errors

Errors

from uform import Status, Error 4.0.0-rc.1 · 3ee5e534

Every fallible entry point raises Error and nothing else, since Mojo allows one error type per function. An Error carries a Status shared with the C interface, so a fault this binding catches before the boundary reports the status the engine would have reported for the same fault:

try:
    _ = Model.load_ram(executor, "missing.safetensors")
except error:
    if error.status == Status.IO:
        pass
    print(error)  # UForm: io [uform_model_load_ram]: ...

An Error keeps the engine mapped while it lives, since its name and message are the engine’s own static text.

API

StructStatusWhy a call into the engine failed, the uform_status_t vocabulary verbatim.1
struct Status

An Error never carries SUCCESS or DEFERRED: only a Deferred reports the latter, and only until its call is final. Library.status_name spells each one as the engine does.

Fields

codeInt32The raw uform_status_t value, kept even when this build does not name it.

Values

SUCCESSStatus(Int32(0))The call completed.
DEFERREDStatus(Int32(1))The call was submitted deferred and is not final yet; the one non-final status.
OUT_OF_MEMORYStatus(Int32(2))Device, pinned or host memory could not be allocated, or the scratch ceiling is too low.
SHAPE_MISMATCHStatus(Int32(3))Item counts, a pixel shape, or a batch envelope disagree with the call or the model.
UNSUPPORTED_LAYOUTStatus(Int32(4))A stride or packing the model cannot read.
UNKNOWN_KINDStatus(Int32(5))A scalar, modality or name this build does not know.
IOStatus(Int32(7))A checkpoint file could not be opened, read or written.
DEVICEStatus(Int32(8))The driver refused or the device faulted; after a fault the executor refuses every later call.
MALFORMEDStatus(Int32(9))Supplied bytes could not be decoded: a checkpoint, an image, a clip or a recording.
INTERNALStatus(Int32(10))The library reported neither success nor a failure, which names a defect rather than a state.
CONFIG_MISMATCHStatus(Int32(13))The request contradicts a frozen configuration, like resuming a checkpoint of another geometry.
CONTENDEDStatus(Int32(14))The call was refused rather than waited for, like a submission to a full deferred table.
CANCELLEDStatus(Int32(15))A progress handler asked the call to stop; it unwound and published nothing.
UNSUPPORTEDStatus(Int32(16))The verb is declared for every residency or model, but this one does not implement it.
INVALID_ARGUMENTStatus(Int32(17))An argument breaks the verb's contract, like a read of a result whose arena a later call rewound.
LIBRARY_MISSINGStatus(Int32(-1))Nothing to dlopen, the binding's own.
SYMBOL_MISSINGStatus(Int32(-2))The library loaded but does not export a symbol the binding needs, the binding's own.
VERSION_MISMATCHStatus(Int32(-3))The library loaded but reports a different major version than the binding's, the binding's own.

Conforms to

Copyable, Deinitable, Equatable, ImplicitlyCopyable, Movable, RegisterPassable, TrivialRegisterPassable
ofLifts a raw uform_status_t, keeping an unnamed one rather than guessing.
def of(code: Int32) -> Self
StructErrorWhat went wrong inside the engine, and which entry point it was about.2
struct Error

Fields

statusStatusWhich class of failure the engine reported.
detailStaticStringThe entry point it was about, for a reader rather than for a branch.
messageOptional[Pointer[Scalar[_c_char_dtype()], ImmUntrackedOrigin]]The engine's own static message, which outlives the call and needs no freeing.
nameOptional[Pointer[Scalar[_c_char_dtype()], ImmUntrackedOrigin]]The engine's spelling of status, absent where no engine named it.
libraryOptional[Library]The engine message and name live in, kept mapped for as long as the error is; Mojo would otherwise unload it at the last handle's last use, while the error is still being read.

Conforms to

Copyable, Deinitable, ImplicitlyCopyable, Movable, Writable
__init__A failure the binding caught before any engine could name it.
def __init__(out self, status: Status, detail: StringSpan[ImmStaticOrigin])

Parameters

statusStatusWhich class of failure it is.
detailStringSpan[ImmStaticOrigin]The entry point or binding type it was about.
write_toWrites the status name, the entry point, and the engine's own message together.
def write_to(self, mut writer: T)

Parameters

writerTmutThe sink the message is appended to.