# Errors in the Swift SDK (/reference/swift-sdk/errors)

Handle the errors a Swift app meets, tell what to do next from each one, and word and report it safely.



Every call on a working copy, `Folders`, a `Server` or a `Client` throws a `MarfaError`. A sign-in throws a [`SignInError`](/reference/swift-sdk/sign-in).

## Handle errors [#handle-errors]

| Member | Gives |
| - | - |
| `message` | **Text fit to show a person.** It can repeat a title or an address. |
| `code()` | The stable name shared with the core and the command line, such as `not_found`. A case's own `code` is the server's refusal code. |
| `server` | A `ServerAnswer?` with the `status`, `code` and `details` the server sent. **`nil` for a failure the device met itself.** |
| `fixedText` | A `FixedErrorText` (`type`, `sentence`, `code`) holding no value the error carries: **safe to report.** The SDK sends nothing itself. |

Four properties say what the app does next. **An error is at most one of a key refusal, transient or a need to hydrate.**

| Property | True for | The app |
| - | - | - |
| `isOffline` | `network`, `noConnection`. A write may still have arrived. | Shows it is offline. Queued writes wait. |
| `isKeyRefusal` | `unauthorized`, `signedOut`, and `copyExpired` or `streamIncomplete` with `credential_ended`. | Asks the person to sign in again. |
| `isTransient` | `network`, `noConnection`, `io`, `storageFull`, `storeBusy`, `rateLimited`, `unnamed`, `keyChanging`, and `server` with status 408 or 500 and above. | Tries later. |
| `isHydrationNeeded` | `copyExpired` for any other reason, `instanceChanged`, `noCursor`, `hydrationIncomplete`, `firstSyncWaiting`. | [Hydrates](/reference/swift-sdk/working-copy#fill-the-copy). |

[Errors](/reference/errors) lists the server's codes.

### Refusals [#refusals]

| Case | Means |
| - | - |
| `notFound(code:message:server:)` | No such row, route or name (404). |
| `unauthorized(code:message:server:)` | **The server doesn't accept the key or token** (401). |
| `forbidden(code:message:server:)` | The key lacks the permission (403), such as `type_not_permitted`. |
| `validation(code:message:details:server:)` | The server refused the values (400 or 422), or the copy did first. `details` holds only the copy's own edge refusals: otherwise read `server?.details`. |
| `server(status:code:message:details:server:)` | Any other answer. |
| `rateLimited(code:message:retryAfterSeconds:server:)` | The server asked for a wait (429). |
| `versionConflict(message:server:)` | **The write's version is no longer current** (409). Read the row again. For a type or a webhook, `currentRevision` or `currentVersion` is the server's now. |
| `unknownType`, `invalid` | No such type in the catalog, or an unusable value. |
| `trashPlanChanged(message:server:)` | A trash's preview no longer matches (409). Nothing was trashed: preview again. |
| `itemBeingRemoved(id:message:)` | A trash or purge holds the item, so the write queued nothing. Ask again once that call returns. |

### Sign-in and the owner [#sign-in-and-the-owner]

| Case | Means |
| - | - |
| `signedOut(origin:message:)`, `noKeychain` | No sign-in for `origin`, or the server ended it: sign in again. The keychain can't be used. |
| `renewalRefused(reason:message:)` | **The sign-in couldn't be renewed, and is kept.** Word it from `reason` (`.refused`, `.redirected` or `.unreadable`). |
| `confirmationRequired(maxAgeSeconds:message:server:)` | **The owner must sign in again** (401 `insufficient_user_authentication`). A [`confirming`](/reference/swift-sdk/sign-in#confirm-its-you) server does it itself. |
| `appSignInRequired(message:server:)` | A key made a call only an app signed in by the owner may make (403). |

### The connection and the server [#the-connection-and-the-server]

| Case | Means |
| - | - |
| `network`, `noConnection` | The request didn't reach the server, its answer was late, or the device is offline. |
| `unnamed(status:message:server:)` | A proxy or the like answered without the server's contract. **Transient.** |
| `redirected(origin:status:location:message:server:)` | A redirect, not followed. |
| `contractMismatch(served:expected:status:writeSent:message:server:)` | The server speaks another contract. **Where `writeSent`, the write may have taken effect:** it stays queued and goes again under its key. |
| `serverTooOld(served:oldest:message:)` | The server's release is older than this build works with. **Asking again can't clear it:** update the server. |
| `noServer`, `wrongServer(expected:got:message:)` | The copy was opened without a server, or the store belongs to another one ([`wrong_server`](/build/fix-a-working-copy#this-file-belongs-to)). |
| `instanceChanged(message:server:)` | Another instance answers (409). Hydrate from it. **The queue is kept.** |
| `copyExpired(reason:message:server:)` | The copy needs a hydration for `reason`. **The queue is kept.** |
| `streamIncomplete(reason:message:server:)` | The event stream ended early. |

A stale copy refuses a drain and a catch-up until hydrated: see [Fix a working copy that can't catch up](/build/fix-a-working-copy).

### The copy and its store [#the-copy-and-its-store]

| Case | Means |
| - | - |
| `hydrationIncomplete` | A read by ID, a view or an edge write came during a hydration. |
| `noCursor`, `noCatalog` | No event position or catalog yet. Hydrate. |
| `notAnswerable` | The copy lacks the data for a local count: [`counts`](/reference/swift-sdk/items#read-items) asks the server. |
| `readingHandle`, `storeBusy` | Another process holds the writer role, or **held the store.** Ask later. |
| `store`, `io`, `decoding`, `storageFull` | A local file couldn't be opened, read or written, or the device is full. |
| `storeDamaged(path:reason:unsent:setAsideStopped:message:)` | SQLite can't read the store. `unsent` counts unsent writes, `nil` where the queue can't be read whole. **`setAsideStopped` blocks removal while a set-aside is unfinished:** call `setAsideDamaged(store:)` again. Test it, never `reason`. |
| `wrongSchema(path:reason:unsent:message:)` | This build can't read the store's shape. |
| `unsentDiffers(path:unsent:message:)` | A removal found other writes than those shown, or a queue it can't read, and removed nothing. |
| `keyChanging`, `closed` | [`use(_:)`](/reference/swift-sdk/working-copy#give-the-copy-a-new-key-and-close-it) is replacing the sign-in: ask again. The copy was closed: open it again. |
| `firstSyncWaiting`, `syncPaused` | A folder's first sync waits, or its sync is paused. |
| `bytesAbsent`, `noRoom(hash:size:free:message:)`, `canceled` | A file's bytes can't be fetched, there is no room for them, or the caller canceled. |
| `fault(message:)` | **The core itself went wrong,** such as a crash. Report it. **Every later call throws `fault`:** close the copy and open it again. |

[A store the copy refuses](/reference/swift-sdk/working-copy#a-store-the-copy-refuses) lists the calls that check, set aside or remove one. `Server` throws `Server.AddressError` and `Server.EnvironmentError`, and `Keychain` throws `Keychain.Failure`.
