NO result from putLocalDocument on iOS

19 views
Skip to first unread message

Brendan Duddridge

unread,
Dec 23, 2015, 7:52:55 PM12/23/15
to Couchbase Mobile
Hi,

I have the following code which saves a document to the localDocument store:

- (void)saveSelectedPeers {


        NSArray *peerTxtRecords = [self.selectedPeers.allValues valueForKey:@"txtRecord"];

       NSError *error = nil;

       CBLJSONDict *peersDict = @{@"peers" : peerTxtRecords};

       BOOL success = [self.databaseDocument.couchDatabase putLocalDocument:peersDict withID:@"selected-peers" error:&error];

       if (!success) {

               TFFLog(@"Error saving selected peer: %@", error);

       }

}


The contents of the peersDict is this:

{

   peers =     (

               {

           dev = "MacBookPro11,3";

           seq = 140885;

           service = "db-85190f3b780d45449c2f17f8d1d86e1f@Voyager";

           user = "Brendan Duddridge";

       }

   );

}


However, the success flag returns NO even though the NSError is nil on the return.

If the result is NO, should there be a reason why put into the NSError parameter?

I'm using the latest Couchbase Lite branch (c5fb2ee30f0a16895c93415d9276b93366296160) from master on iOS 9.2.

Thanks,

Brendan

Jens Alfke

unread,
Dec 24, 2015, 7:52:01 PM12/24/15
to mobile-c...@googlegroups.com

On Dec 23, 2015, at 4:52 PM, Brendan Duddridge <bren...@gmail.com> wrote:

However, the success flag returns NO even though the NSError is nil on the return.

That would be a bug … I’m looking at the implementation (for ForestDB) but I can’t see a code path that would cause this. You’re using ForestDB, right?

Does a local doc with that ID already exist when this bug occurs? That is, does the first call with this docID succeed?

—Jens

Jens Alfke

unread,
Dec 24, 2015, 8:04:52 PM12/24/15
to mobile-c...@googlegroups.com
I couldn’t find a bug by inspecting the SQLite code-path either.
The unit test didn’t cover updating an existing doc, but I added a few lines to do that, and the test passes.

Revisiting your code, I suspect you’ve fallen prey to the old “unexpected nil receiver” problem — try adding an assertion right above that line to test that self.databaseDocument.couchDatabase != nil.

—Jens

Brendan Duddridge

unread,
Dec 25, 2015, 12:14:40 AM12/25/15
to Couchbase Mobile
Hi Jens,

Thanks for answering. And on Christmas Eve too!

I'm actually using SQLite with SQLCipher at the moment.

And no, the database file is not nil. I just printed it out and it's definitely there:

2015-12-24 22:13:17.562 Tap Forms[7006:3960085] database: CBLDatabase[<0x11c723410>db-85190f3b780d45449c2f17f8d1d86e1f]

2015-12-24 22:13:17.562 Tap Forms[7006:3960085] Error saving selected peer: (null)


I'll keep investigating.

Brendan Duddridge

unread,
Dec 25, 2015, 12:17:04 AM12/25/15
to Couchbase Mobile
Does a local doc with that ID already exist when this bug occurs? That is, does the first call with this docID succeed?

Yes, the document already exists. I'm updating the local document to store the sequence number and the peer information to facilitate sync management in the peer-to-peer environment.


On Thursday, December 24, 2015 at 5:52:01 PM UTC-7, Jens Alfke wrote:
Reply all
Reply to author
Forward
0 new messages