Ugraded to latest couchbase lite v1.3.1 - App crashed with exception when saving data to database

i have not encrypted my database, but still why am i getting this error?

WARNING: CBL_SQLiteStorage: database is unreadable (err 14) {at -[CBL_SQLiteStorage decryptWithKey:error:]:284}
2017-01-05 14:30:07.036 BEST[416:119015] *** Assertion failure in +[CCTest modelForDocument:], /Users/jenkins/jenkins/workspace/couchbase-lite-ios-builds/couchbase-lite-ios-community/Source/API/CBLModel.m:78
2017-01-05 14:30:07.037 BEST[416:119015] *** Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘Invalid parameter not satisfying: document’

When i check the source code, i could see this particular warning is displayed inside the method

  • (BOOL) decryptWithKey: (CBLSymmetricKey*)encryptionKey error: (NSError**)outError;

Anyone else faced this issue already? please guide me on this.Thanks

-decryptWithKey: gets called whether or not a key is given. If there’s no key, it just verifies that the database is useable by running a quick no-op query.

Error 14 is SQLITE_CANTOPEN, described in sqlite3.h as “Unable to open the database file”.

What’s probably going on here is that your app is running while in the background (maybe it got a push notification), but you’ve configured the app’s filesystem protection entitlement such that files cannot be opened while in the background. So SQLite fails to open the database file.

The most direct way to fix this is to set more lenient file protection options when you create the CBLManager — look at the field CBLManagerOptions.fileProtection in CBLManager.h.

We’re addressing this partly in 1.4 by improving the error handling, but the fact remains that if you want to run in the background you need to configure access to files that will be needed then.

1 Like

Oh also, the reason for the crash is that you called +[CCTest modelForDocument:] and passed a nil document parameter, which is illegal. This probably happened because the database failed to open so you couldn’t read a document, but you didn’t check for errors before trying to use the (nil) CBLDocument reference.

Thanks jens.will check that issue

hi. i’m getting the same CBL_SQLitesStorage error. Can you show me how to implement this fileprotection? thanks

Look at the field CBLManagerOptions.fileProtection in CBLManager.h.
You should also read the iOS docs on file protection, if you’re not familiar with it.