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

MemberGives
messageText 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.
serverA ServerAnswer? with the status, code and details the server sent. nil for a failure the device met itself.
fixedTextA 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.

PropertyTrue forThe app
isOfflinenetwork, noConnection. A write may still have arrived.Shows it is offline. Queued writes wait.
isKeyRefusalunauthorized, signedOut, and copyExpired or streamIncomplete with credential_ended.Asks the person to sign in again.
isTransientnetwork, noConnection, io, storageFull, storeBusy, rateLimited, unnamed, keyChanging, and server with status 408 or 500 and above.Tries later.
isHydrationNeededcopyExpired for any other reason, instanceChanged, noCursor, hydrationIncomplete, firstSyncWaiting.Hydrates.

Errors lists the server's codes.

Refusals

CaseMeans
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, invalidNo 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

CaseMeans
signedOut(origin:message:), noKeychainNo 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 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

CaseMeans
network, noConnectionThe 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).
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.

The copy and its store

CaseMeans
hydrationIncompleteA read by ID, a view or an edge write came during a hydration.
noCursor, noCatalogNo event position or catalog yet. Hydrate.
notAnswerableThe copy lacks the data for a local count: counts asks the server.
readingHandle, storeBusyAnother process holds the writer role, or held the store. Ask later.
store, io, decoding, storageFullA 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, closeduse(_:) is replacing the sign-in: ask again. The copy was closed: open it again.
firstSyncWaiting, syncPausedA folder's first sync waits, or its sync is paused.
bytesAbsent, noRoom(hash:size:free:message:), canceledA 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.

On this page