Swift · Errors

Errors

import UForm 4.0.0-rc.1 · 3ee5e534

UFormError is the only error the SDK throws, and every method says so with throws(UFormError), so a catch reads error.status with no cast. Status has one constant per uform_status_*_k of the C interface, and its description spells it as the library does, like invalid-argument.

do {
    _ = try Model.loadRam(path: "missing.safetensors")
} catch {
    print(error.status, error.message) // io The checkpoint could not be opened for reading
}

Scalar, Mood and every other closed set read a spelling back with init?(name:), and nil for one the library does not spell.

API

StructStatusWhat went wrong, in the vocabulary the library and every binding share - one constant per uform_status_*_k, carrying the C enumerator itself.17
Types.swift:18 ↗
struct Status

A UFormError never carries success or deferred; a Deferred call reports both.

Conforms to

Hashable, Sendable, CustomStringConvertible, Equatable
successThe call succeeded and carries no message.
Types.swift:23 ↗
static let success: Status
deferredThe call was submitted deferred and is not final yet.
Types.swift:25 ↗
static let deferred: Status
outOfMemoryDevice, pinned or host memory could not be allocated.
Types.swift:27 ↗
static let outOfMemory: Status
shapeMismatchItem counts, a pixel shape or a batch envelope disagree with the call or the model.
Types.swift:29 ↗
static let shapeMismatch: Status
unsupportedLayoutA stride or packing the model cannot read.
Types.swift:31 ↗
static let unsupportedLayout: Status
unknownKindA scalar, modality or name this build does not know.
Types.swift:33 ↗
static let unknownKind: Status
ioA checkpoint file could not be opened, read or written.
Types.swift:35 ↗
static let io: Status
deviceThe driver refused or the device faulted.
Types.swift:37 ↗
static let device: Status
malformedSupplied bytes could not be decoded.
Types.swift:39 ↗
static let malformed: Status
internalThe library reported neither success nor a failure.
Types.swift:41 ↗
static let `internal`: Status
configMismatchThe request contradicts a frozen configuration.
Types.swift:43 ↗
static let configMismatch: Status
contendedA call was refused rather than waited for - a full deferred table, or an arena serving another call.
Types.swift:46 ↗
static let contended: Status
cancelledA progress handler asked the call to stop; it unwound and published nothing.
Types.swift:48 ↗
static let cancelled: Status
unsupportedThe verb is declared, but this residency or model does not implement it.
Types.swift:50 ↗
static let unsupported: Status
invalidArgumentAn argument breaks the verb's contract.
Types.swift:52 ↗
static let invalidArgument: Status
descriptionThe status as the library spells it, like invalid-argument.
Types.swift:55 ↗
var description: String { get }

Calls uform_status_name.

initReads a spelling back, and nil for one no status carries.
Types.swift:58 ↗
init?(name: String)

Calls uform_status_from_name.

StructUFormErrorOne failed call: a status every caller can branch on, and the detail the status cannot carry.3
Types.swift:67 ↗
struct UFormError

Conforms to

Error, CustomStringConvertible, Equatable, Sendable
statusThe failure identity, shared with every other SDK.
Types.swift:69 ↗
let status: Status
messageThe library's static detail, or this binding's own when it refused the call.
Types.swift:71 ↗
let message: String
descriptionThe status and message, as uform: <status>: <message>.
Types.swift:74 ↗
var description: String { get }