# Errors

> USearch for Swift

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

```swift
do {
    try index.reserve(1 << 40)
} catch {
    print(error.status, error.message)
}
```

NumKong exports a `Status` of its own, so a file importing both spells this one `USearch.Status`.

`import USearch`

## Status

What went wrong, in the vocabulary the engine and this binding share - one constant per engine status.

```swift
struct Status
```

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

A [`USearchError`](#USearchError) never carries [`success`](#success) or [`deferred`](#deferred); a [`Deferred`](https://www.unum.cloud/docs/usearch/swift/executors.md#Deferred) call reports both.

Conforms to: `Hashable`, `Sendable`, `CustomStringConvertible`, `Equatable`

## success

The call succeeded and carries no message.

```swift
static let success: Status
```

## deferred

The call was submitted deferred and is not final yet.

```swift
static let deferred: Status
```

## outOfMemory

An allocation or reservation could not be satisfied.

```swift
static let outOfMemory: Status
```

## shapeMismatch

Dimensionality or row counts disagree.

```swift
static let shapeMismatch: Status
```

## unsupportedLayout

A stride or packing the engine cannot traverse.

```swift
static let unsupportedLayout: Status
```

## unknownKind

A scalar, metric, or residency tag this build does not know.

```swift
static let unknownKind: Status
```

## readOnly

A mutating verb reached a handle that serves its checkpoint in place.

```swift
static let readOnly: Status
```

## io

A file could not be opened, read, written, or parsed.

```swift
static let io: Status
```

## device

A device could not be selected, or its memory could not be claimed.

```swift
static let device: Status
```

## malformed

A caller-supplied representation could not be decoded.

```swift
static let malformed: Status
```

## internal

The library reported neither success nor a failure.

```swift
static let `internal`: Status
```

## overflow

A hard design ceiling was reached, like the 32-bit ID space.

```swift
static let overflow: Status
```

## uninitialized

The verb needs a prior successful reservation that never happened.

```swift
static let uninitialized: Status
```

## configMismatch

The request contradicts an already-frozen configuration.

```swift
static let configMismatch: Status
```

## contended

A call was refused rather than waited for - a full deferred table, a busy arena, or a blocking call from inside a callback of the executor it would wait on.

```swift
static let contended: Status
```

## cancelled

A progress handler asked the operation to stop; what the finished increments leave behind is each verb's own contract.

```swift
static let cancelled: Status
```

## unsupported

The verb is declared for every residency but this one does not implement it.

```swift
static let unsupported: Status
```

## invalidArgument

An argument breaks the verb's contract.

```swift
static let invalidArgument: Status
```

## description

The status rendered as the library spells it, like `invalid-argument`.

```swift
var description: String { get }
```

## init

Reads a spelling back, and nil for one no status carries.

```swift
init?(name: String)
```

## USearchError

One failed call: a status every caller can branch on, and the detail the status cannot carry.

```swift
struct USearchError
```

Conforms to: `Error`, `CustomStringConvertible`, `Equatable`, `Sendable`

## status

The failure identity, shared with every other SDK.

```swift
let status: Status
```

## message

The library's static detail, or this binding's own when it rejected the call.

```swift
let message: String
```

## cause

What a caller's closure threw to stop the call, and nil for every other failure.

```swift
let cause: (any Swift.Error)?
```

## description

```swift
var description: String { get }
```

## ==

Equal in status and message, which is as far as an arbitrary cause compares.

```swift
static func == (left: USearchError, right: USearchError) -> Bool
```

