Zig · Errors

Errors

const usearch = @import("usearch");const Status = @import("usearch").Status;const Outcome = @import("usearch").Outcome; 3.0.0-rc.1 · 4c3e5023

Every verb answers Error!T, one error per final status of the C interface. The engine checks every shape it can see; the binding checks only what never crosses the boundary, like a key run longer than its rows, and reports the status the engine would have. The engine’s static detail message rides an Outcome you lend: diagnosed(&outcome) on the index or a blocking receiver copies every call’s final outcome into it, a constructor’s config takes one as diagnostics, and a Deferred answers its own through message. The binding’s own refusals land there too, with a message of their own. One set covers every verb rather than a narrower one per verb, since nothing in the ABI bounds which status a given call may report.

var outcome: usearch.Outcome = .{};
_ = index.on(executor).diagnosed(&outcome).search(queries, 10, &arena, .{}) catch |failure| {
    std.log.err("{s}: {s}", .{ @errorName(failure), outcome.text() });
    return failure;
};
var copy = try usearch.DenseIndex.loadRam("index.safegraphs", .{ .diagnostics = &outcome });

Status, Scalar, Mood, Residency and DenseMetric carry the C enumerators’ values, and their name and fromName spell them through the C name tables, fromName answering null for text no table spells.

std.debug.print("{s}\n", .{usearch.Status.contended.name()}); // contended
const metric = usearch.DenseMetric.fromName("inner") orelse return error.UnknownMetric;

API

Types

ErrorOne error per final failure status, so @errorName carries as much as the status itself does.
pub const Error = error

Zig error values hold no payload, so neither the static message nor the symbol that failed can travel with the error. Lend an Outcome as a call's diagnostics, or read Deferred.message, where that detail matters.

One set serves every verb rather than a narrower one per verb: the engine answers each call through the same Outcome, and nothing in the ABI bounds which status a given verb may report, so a narrower signature would be a promise this boundary cannot keep.

Values

OutOfMemory
ShapeMismatch
UnsupportedLayout
UnknownKind
ReadOnly
Io
Device
Malformed
Internal
Overflow
Uninitialized
ConfigMismatch
Contended
Cancelled
Unsupported
InvalidArgument
EnumStatusWhat went wrong, mirroring usearch_status_t value-for-value.2
types.zig:54 ↗
pub const Status = enum(c_int)

Non-exhaustive, so a status a newer engine reports arrives intact rather than coerced.

Values

success0The call completed; the outcome's message carries nothing.
deferred1The call was submitted deferred and is not final yet; the one non-final status.
out_of_memory2An allocation or reservation could not be satisfied.
shape_mismatch3Dimensionality or row counts disagree.
unsupported_layout4A stride or packing the engine cannot traverse.
unknown_kind5A scalar, metric, or residency tag this build does not know.
read_only6A mutating verb on a handle that serves its checkpoint in place.
io7A file could not be opened, read, written, or parsed.
device8A device could not be selected, or its memory could not be claimed.
malformed9A caller-supplied representation could not be decoded.
internal10The library reported neither success nor a failure - a defect, not a state.
overflow11A hard design ceiling was reached, like the 32-bit ID space.
uninitialized12The verb needs a prior successful reservation that never happened.
config_mismatch13The request contradicts an already-frozen configuration.
contended14The call was refused rather than waited for - a full deferred table, or an arena serving another call.
cancelled15A progress handler asked the operation to stop.
unsupported16The verb is declared for every residency but this one does not implement it.
invalid_argument17An argument breaks the verb's contract.
nameThe canonical spelling, "unrecognized" for a value no status carries.
types.zig:94 ↗
pub fn name(self: Status) [:0]const u8

Calls usearch_status_name.

fromNameReads a spelling back, or null when no status spells it.
types.zig:99 ↗
pub fn fromName(text: []const u8) ?Status

Calls usearch_status_from_name.

StructOutcomeOutcome of one call: a status to branch on, and a static message carrying what the status cannot.3
types.zig:138 ↗
pub const Outcome = extern struct

Mirrors usearch_outcome_t, which every verb's argument structure points at.

Every verb answers Error!T, and a caller wanting the message too lends an Outcome as the call's diagnostics, which the call's final outcome is copied into. Messages are static and need no deallocation.

Fields

statusStatusWhat the call reported; .success is the only non-error.
message?[*:0]const u8Static, English detail, null exactly when the status is .success.
checkLifts the status into the error set; .success is the only non-error.
types.zig:145 ↗
pub fn check(self: Outcome) Error!void
textThe static detail the status could not carry; empty where the call reported none.
types.zig:151 ↗
pub fn text(self: Outcome) [:0]const u8
checkIntoCopies the outcome into diagnostics where one was lent, then lifts it as check does.
types.zig:156 ↗
pub fn checkInto(self: Outcome, diagnostics: ?*Outcome) Error!void