Go · Errors

Errors

import "github.com/unum-cloud/USearch/golang" 3.0.0-rc.1 · 4c3e5023

Every failure carries a status shared with the C interface, so a fault this binding catches before the boundary reports the identity the engine would have reported for the same fault. A Status is itself an error, so errors.Is matches any failure carrying it, and an *usearch.Error adds its message:

if err := index.Insert(keys, vectors, nil); err != nil {
	if errors.Is(err, usearch.StatusShapeMismatch) {
		// the keys and the rows disagree
}

	var failure *usearch.Error
	if errors.As(err, &failure) {
		fmt.Println(failure.Status, failure.Message)
}
}

Status, like Mood, Residency, Traversal, DenseMetric and Scalar, carries the C enumerators’ values, and its String spells the name the C tables own. StatusUnsupported marks a verb declared for every residency that this one does not implement yet, and StatusContended a call refused rather than waited for.

API

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

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

ErrorError implements the error interface.
types.go:116 ↗
func (failure *Error) Error() string
UnwrapUnwrap exposes the status, which is what errors.Is compares.
types.go:121 ↗
func (failure *Error) Unwrap() error
EnumStatusStatus names what went wrong, in a vocabulary shared by the engine and by this binding.2
types.go:53 ↗
type Status int32

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

A Status is an error, so errors.Is(err, usearch.StatusReadOnly) 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 an allocation or reservation could not be satisfied.
StatusShapeMismatchStatusShapeMismatch means dimensionality or row counts disagree.
StatusUnsupportedLayoutStatusUnsupportedLayout means a stride or packing the engine cannot traverse.
StatusUnknownKindStatusUnknownKind means a scalar, metric, or residency tag this build does not know.
StatusReadOnlyStatusReadOnly means a mutating verb reached a handle that serves its checkpoint in place.
StatusIOStatusIO means a file could not be opened, read, written, or parsed.
StatusDeviceStatusDevice means a device could not be selected, or its memory could not be claimed.
StatusMalformedStatusMalformed means a caller-supplied representation could not be decoded.
StatusInternalStatusInternal means the library reported neither success nor a failure.
StatusOverflowStatusOverflow means a hard design ceiling was reached, like the 32-bit ID space.
StatusUninitializedStatusUninitialized means the verb needs a prior successful reservation that never happened.
StatusConfigMismatchStatusConfigMismatch means the request contradicts an already-frozen configuration.
StatusContendedStatusContended means the call was refused rather than waited for, like a submission to a full deferred table, or an arena still serving another call.
StatusCancelledStatusCancelled means a progress handler asked the operation to stop; it unwound and published nothing, so the handle carries whatever it did before the call.
StatusUnsupportedStatusUnsupported means the verb is declared for every residency but this one does not implement it; a caller picks another residency.
StatusInvalidArgumentStatusInvalidArgument means an argument breaks the verb's contract, like a required value left nil.
ErrorError implements the error interface, so a bare Status is an errors.Is target.
types.go:106 ↗
func (status Status) Error() string
StringString renders the status as the library spells it.
types.go:101 ↗
func (status Status) String() string