Python · Errors

Errors

import usearchfrom usearch import Error 3.0.0-rc.1 · 4c3e5023

Every failure raises a subclass of usearch.Error, itself a RuntimeError, and each carries the status the C ABI reported as its status attribute, a usearch.Status member:

try:
    index.on(pool).search(queries, 10, arena, progress=lambda completed, total: completed < 100)
except usearch.CancelledError:
    ...  # The handler stopped the call, which published nothing
except usearch.Error as error:
    print(error.status)  # Status.SHAPE_MISMATCH, Status.READ_ONLY, Status.DEVICE, ...

usearch.Status is an enum.IntEnum valued as usearch_status_t. SUCCESS and DEFERRED raise nothing, and every other member has its own class, which also derives the built-in naming the same fault where one exists:

  • OUT_OF_MEMORY → OutOfMemoryError, a MemoryError
  • SHAPE_MISMATCH → ShapeMismatchError, a ValueError
  • UNSUPPORTED_LAYOUT → UnsupportedLayoutError, a ValueError
  • UNKNOWN_KIND → UnknownKindError, a ValueError
  • READ_ONLY → ReadOnlyError
  • IO → InputOutputError, an OSError
  • DEVICE → DeviceError
  • MALFORMED → MalformedError, a ValueError
  • INTERNAL → InternalError
  • OVERFLOW → CapacityOverflowError, an OverflowError
  • UNINITIALIZED → UninitializedError
  • CONFIG_MISMATCH → ConfigMismatchError, a ValueError
  • CONTENDED → ContendedError
  • CANCELLED → CancelledError
  • UNSUPPORTED → UnsupportedError, a NotImplementedError
  • INVALID_ARGUMENT → InvalidArgumentError, a ValueError

So except ValueError catches a ShapeMismatchError, except OSError an InputOutputError, and except MemoryError an OutOfMemoryError. A failure the binding catches before the boundary raises the class the engine would have raised for the same fault. Arguments the binding refuses raise at the call, while the engine’s refusals of a deferred call raise at await or wait(), as many times as they are asked.

API

Types

StatusWhat a call finished with: Error.status and Deferred.status.
__init__.py:139 ↗
class Status(IntEnum)

Values

SUCCESS0The call succeeded.
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, residency, traversal or relation 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 key, buffer or checkpoint could not be decoded.
INTERNAL10The library reported neither success nor a failure, which names a defect.
OVERFLOW11A hard design ceiling was reached, like the 32-bit ID space; a smaller request cannot help.
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, like a submission to a full deferred table.
CANCELLED15A progress handler stopped the call, which published nothing.
UNSUPPORTED16This residency, traversal or build does not implement the verb; no retry can help.
INVALID_ARGUMENT17An argument breaks the verb's contract.
OutOfMemoryErrorAn allocation or reservation could not be satisfied.
__init__.py:326 ↗
class OutOfMemoryError(Error, MemoryError)
ShapeMismatchErrorDimensionality or row counts disagree.
__init__.py:329 ↗
class ShapeMismatchError(Error, ValueError)
UnsupportedLayoutErrorA stride or packing the engine cannot traverse.
__init__.py:332 ↗
class UnsupportedLayoutError(Error, ValueError)
UnknownKindErrorA scalar, metric, or residency this build does not know.
__init__.py:335 ↗
class UnknownKindError(Error, ValueError)
ReadOnlyErrorA mutating verb on a handle that serves its checkpoint in place.
__init__.py:338 ↗
class ReadOnlyError(Error)
InputOutputErrorA file could not be opened, read, written, or parsed.
__init__.py:341 ↗
class InputOutputError(Error, OSError)
DeviceErrorA device could not be selected, or its memory could not be claimed.
__init__.py:344 ↗
class DeviceError(Error)
MalformedErrorA representation could not be decoded - a key, a buffer, a checkpoint.
__init__.py:347 ↗
class MalformedError(Error, ValueError)
InternalErrorThe library reported neither success nor a failure - a defect.
__init__.py:350 ↗
class InternalError(Error)
CapacityOverflowErrorA hard design ceiling was reached; a smaller request cannot help.
__init__.py:353 ↗
class CapacityOverflowError(Error, OverflowError)
UninitializedErrorThe handle is not ready for the verb - absorbed as a donor, or closed.
__init__.py:356 ↗
class UninitializedError(Error)
ConfigMismatchErrorThe request contradicts an already-frozen configuration.
__init__.py:359 ↗
class ConfigMismatchError(Error, ValueError)
ContendedErrorAn executor's deferred table, an arena, or a walk is already serving another call.
__init__.py:362 ↗
class ContendedError(Error)
CancelledErrorA progress handler stopped the call, which published nothing.
__init__.py:365 ↗
class CancelledError(Error)
UnsupportedErrorThis residency does not implement the verb; pick another residency.
__init__.py:368 ↗
class UnsupportedError(Error, NotImplementedError)
InvalidArgumentErrorAn argument breaks the verb's contract.
__init__.py:371 ↗
class InvalidArgumentError(Error, ValueError)
ClassErrorThe base of every failure the library reports, one subclass per failing Status.1
lib.pyi:321 ↗
class Error(RuntimeError)
status
lib.pyi:324 ↗
status: Status