Errors in the Swift SDK
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.
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. |
Errors lists the server's codes.
Refusals
| Case | Means |
|---|---|
not | 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. |
rate | The server asked for a wait (429). |
version | 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. |
trash | A trash's preview no longer matches (409). Nothing was trashed: preview again. |
item | A trash or purge holds the item, so the write queued nothing. Ask again once that call returns. |
Sign-in and the owner
| Case | Means |
|---|---|
signed, noKeychain | No sign-in for origin, or the server ended it: sign in again. The keychain can't be used. |
renewal | The sign-in couldn't be renewed, and is kept. Word it from reason (.refused, .redirected or .unreadable). |
confirmation | The owner must sign in again (401 insufficient_). A confirming server does it itself. |
app | A key made a call only an app signed in by the owner may make (403). |
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. |
contract | The server speaks another contract. Where writeSent, the write may have taken effect: it stays queued and goes again under its key. |
server | The server's release is older than this build works with. Asking again can't clear it: update the server. |
noServer, wrong | The copy was opened without a server, or the store belongs to another one (wrong_server). |
instance | Another instance answers (409). Hydrate from it. The queue is kept. |
copy | The copy needs a hydration for reason. The queue is kept. |
stream | 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.
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 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. |
store | 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. |
wrong | This build can't read the store's shape. |
unsent | A removal found other writes than those shown, or a queue it can't read, and removed nothing. |
keyChanging, closed | use(_:) 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, no, 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 lists the calls that check, set aside or remove one. Server throws Server.AddressError and Server.EnvironmentError, and Keychain throws Keychain.Failure.