# Errors

> 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.

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

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.

```go
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

### Struct `Error`

Error is one failed call: a status every caller can branch on, and the detail the status cannot carry.2

[types.go:132 ↗](https://github.com/unum-cloud/UForm/blob/c58749fe4bb208356cc78a87357ab007041c515b/types.go#L132)

```go
type Error struct {
    Status  Status
    Message string
}
```

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

#### `Error`

Error implements the error interface.

[types.go:138 ↗](https://github.com/unum-cloud/UForm/blob/c58749fe4bb208356cc78a87357ab007041c515b/types.go#L138)

```go
func (failure *Error) Error() string
```

#### `Unwrap`

Unwrap exposes the status, which is what errors.Is compares.

[types.go:143 ↗](https://github.com/unum-cloud/UForm/blob/c58749fe4bb208356cc78a87357ab007041c515b/types.go#L143)

```go
func (failure *Error) Unwrap() error
```

### Enum `Status`

Status 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 ↗](https://github.com/unum-cloud/UForm/blob/c58749fe4bb208356cc78a87357ab007041c515b/types.go#L69)

```go
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

| `StatusSuccess` | | StatusSuccess means the call completed and carries no message. |
| - | - | - |
| `StatusDeferred` | | StatusDeferred means the call was submitted deferred and is not final yet. |
| `StatusOutOfMemory` | | StatusOutOfMemory means device, pinned or host memory could not be allocated. |
| `StatusShapeMismatch` | | StatusShapeMismatch means item counts, a pixel shape or a batch envelope disagree. |
| `StatusUnsupportedLayout` | | StatusUnsupportedLayout means a stride or packing the model cannot read. |
| `StatusUnknownKind` | | StatusUnknownKind means a scalar, modality or name this build does not know. |
| `StatusIO` | | StatusIO means a checkpoint file could not be opened, read or written. |
| `StatusDevice` | | StatusDevice means the driver refused or the device faulted, or the build carries no GPU. |
| `StatusMalformed` | | StatusMalformed means supplied bytes could not be decoded: a checkpoint, an image, a clip or a recording. |
| `StatusInternal` | | StatusInternal means the library reported neither success nor a failure. |
| `StatusOverflow` | | StatusOverflow means a count would pass the largest value its type holds. |
| `StatusUninitialized` | | StatusUninitialized means the handle the call operates on is closed or was never opened. |
| `StatusConfigMismatch` | | StatusConfigMismatch means the request contradicts a frozen configuration. |
| `StatusContended` | | StatusContended means the call was refused rather than waited for: another call holds its executor or arena. |
| `StatusCancelled` | | StatusCancelled means a progress handler asked the call to stop; it unwound and published nothing. |
| `StatusUnsupported` | | StatusUnsupported means the verb is declared but this residency or model does not implement it, like a modality the model was not trained on. |
| `StatusInvalidArgument` | | StatusInvalidArgument means an argument breaks the verb's contract, like a required value left nil. |

##### `StatusFromName`

StatusFromName reads a status back from the spelling [Status.String](#String) renders.

[types.go:121 ↗](https://github.com/unum-cloud/UForm/blob/c58749fe4bb208356cc78a87357ab007041c515b/types.go#L121)

```go
func StatusFromName(name string) (Status, error)
```

##### `Error`

Error implements the error interface, so a bare Status is an errors.Is target.

[types.go:128 ↗](https://github.com/unum-cloud/UForm/blob/c58749fe4bb208356cc78a87357ab007041c515b/types.go#L128)

```go
func (status Status) Error() string
```

##### `String`

String renders the status as the library spells it.

[types.go:116 ↗](https://github.com/unum-cloud/UForm/blob/c58749fe4bb208356cc78a87357ab007041c515b/types.go#L116)

```go
func (status Status) String() string
```
