Error handling in CBL

Looking at the documentation for the Couchbase Lite Database and Query classes, I see that the query, save and delete operations throw “An error on a failure.”.

  1. What kinds of errors can be thrown in these cases and what is the best way to identify them?
  2. Which of these errors are recoverable and what actions can be taken in an app to recover?
  3. What state is the database left in after these errors occur?

Which platform are you referring to?

Hi Jim, thanks for taking a look. I’m primarily looking at iOS Swift right now but I also checked Android to see if there were any hints and found the same kind of vague description.

Swift I am not completely sure how it is handled, but on Objective-C NSError is used to return an error code in the CouchbaseLite domain. As far as Java, it should throw an exception with a description of the problem. None of these will ever affect the integrity of the database. If the operation fails, the database will simply be in its previous state. Here is a list of error codes that we define, some of which could be returned from these sorts of operations.

It’s fairly rare for an error to happen and so most of them are not recoverable. The ones that are have more to do with contents of the document being invalid, or trying to perform an operation on a closed database.

1 Like

Thanks Jim, that’s exactly the information I was looking for.