Go · Errors

Errors

import "github.com/unum-cloud/uform" 4.0.0-rc.1 · c58749fe

Ask your coding agent about this page, or add the docs server to it

curl -s 'https://www.unum.cloud/docs/uform/go/errors.md' | claude -p "How would this fit my code?"

Every fallible call answers an error whose *Error carries a Status and the library’s static Message, and a bare Status is an error too, so errors.Is matches either. A failure the binding catches before the call crosses the boundary reports the status the library would have used.

encoded, err := model.On(executor).TextEncode(texts, uform.EncodeOutputsEmbeddings, uform.ScalarF32, arena, nil)
switch {
case errors.Is(err, uform.StatusContended):
	fmt.Println("the arena serves another call")
case err != nil:
	fmt.Println(err)
default:
	fmt.Println(encoded.Embeddings.Count(), "items")
}

Status carries the C enumerators’ values, and StatusDeferred reaches only Deferred.Status. Status, Scalar, Mood, CPUClass, GPUClass, GPUVendor, Modality, Objective, Negatives, MultimemTier, PairLossForm and LateInteractionSide print the names the C tables own through String, such as "shape-mismatch" or "intel-haswell". A panic inside a progress handler crashes the process, since it cannot unwind through the library.

API

StructErrorError is one failed call: a status every caller can branch on, and the detail the status cannot carry.2
types.go:132 ↗
type Error struct {
    Status  Status
    Message string
}

Reach the status with errors.Is or errors.As.

ErrorError implements the error interface.
types.go:138 ↗
func (failure *Error) Error() string
UnwrapUnwrap exposes the status, which is what errors.Is compares.
types.go:143 ↗
func (failure *Error) Unwrap() error
EnumStatusStatus names what went wrong, numbered as the C header and USearch number it, so one failure carries one identity across both libraries.3
types.go:69 ↗
type Status int32

Validation performed here before a call crosses reports the status the library would have reported for the same fault.

A Status is an error, so errors.Is(err, uform.StatusUnsupported) matches any failure carrying it.

Values

StatusSuccessStatusSuccess means the call completed and carries no message.
StatusDeferredStatusDeferred means the call was submitted deferred and is not final yet.
StatusOutOfMemoryStatusOutOfMemory means device, pinned or host memory could not be allocated.
StatusShapeMismatchStatusShapeMismatch means item counts, a pixel shape or a batch envelope disagree.
StatusUnsupportedLayoutStatusUnsupportedLayout means a stride or packing the model cannot read.
StatusUnknownKindStatusUnknownKind means a scalar, modality or name this build does not know.
StatusIOStatusIO means a checkpoint file could not be opened, read or written.
StatusDeviceStatusDevice means the driver refused or the device faulted, or the build carries no GPU.
StatusMalformedStatusMalformed means supplied bytes could not be decoded: a checkpoint, an image, a clip or a recording.
StatusInternalStatusInternal means the library reported neither success nor a failure.
StatusOverflowStatusOverflow means a count would pass the largest value its type holds.
StatusUninitializedStatusUninitialized means the handle the call operates on is closed or was never opened.
StatusConfigMismatchStatusConfigMismatch means the request contradicts a frozen configuration.
StatusContendedStatusContended means the call was refused rather than waited for: another call holds its executor or arena.
StatusCancelledStatusCancelled means a progress handler asked the call to stop; it unwound and published nothing.
StatusUnsupportedStatusUnsupported means the verb is declared but this residency or model does not implement it, like a modality the model was not trained on.
StatusInvalidArgumentStatusInvalidArgument means an argument breaks the verb's contract, like a required value left nil.
StatusFromNameStatusFromName reads a status back from the spelling Status.String renders.
types.go:121 ↗
func StatusFromName(name string) (Status, error)
ErrorError implements the error interface, so a bare Status is an errors.Is target.
types.go:128 ↗
func (status Status) Error() string
StringString renders the status as the library spells it.
types.go:116 ↗
func (status Status) String() string