createPullReplication returns nil

34 views
Skip to first unread message

Herman Chan

unread,
Dec 1, 2015, 12:11:25 PM12/1/15
to Couchbase Mobile
Hi there,

I can see that [CBLDatabase createPullReplication] can return nil (mark nullable), when will that happen?  Moreover, what should we do when that happens?

Herman

Jens Alfke

unread,
Dec 1, 2015, 12:22:40 PM12/1/15
to mobile-c...@googlegroups.com

On Dec 1, 2015, at 9:11 AM, Herman Chan <herm...@gmail.com> wrote:

I can see that [CBLDatabase createPullReplication] can return nil (mark nullable), when will that happen?  Moreover, what should we do when that happens?

It actually can’t; the ‘nullable’ annotation was a mistake. Fixed on the master branch.

—Jens

Herman Chan

unread,
Dec 1, 2015, 12:31:24 PM12/1/15
to Couchbase Mobile
Hi Jens,

Hmmm. I am getting crash log that says it can be nil.  here is the code

- (void) createDatabaseAndStartReplication:(NSArray*)groupIds {


    NSError *__autoreleasing error;


    for (NSString *groupId in groupIds) {


        NSString *databaseName = [NSString stringWithFormat:@"group_%@", groupId];


        CBLDatabase *database = [self.server databaseNamed:databaseName error:&error];


        HubCredential *credInfo = [[HubCredentialService sharedInstance] credInfo];


        NSString *url;


        if ([HubUserDefaults hubEmbedUserPassInReplicateURL]) {


            url = [NSString stringWithFormat:@"%@%@",REMOTE_COUCH_DB_URL, databaseName];


        }

       else {

           url = [NSString stringWithFormat:@"%@%@",REMOTE_COUCH_DB_URL, databaseName];

       }

       CBLReplication *pullRepl = [database createPullReplication:[NSURL URLWithString:url]];

       CBLReplication *pushRepl = [database createPushReplication:[NSURL URLWithString:url]];

       pullRepl.authenticator = [CBLAuthenticator basicAuthenticatorWithName:credInfo.userName password:credInfo.password];

        pushRepl.authenticator =[CBLAuthenticator basicAuthenticatorWithName:credInfo.userName password:credInfo.password];


        [self addReplications:@[pullRepl, pushRepl]];

        [self setupPushFilters:database];

   }

}

- (void) addReplications: (NSArray*)replications {

   for (CBLReplication* repl in replications) {

       [self addReplication: repl];

   }

}


- (void) addReplication: (CBLReplication*)repl {

   if (![self.replications containsObject: repl]) {

       repl.continuous = YES;

       [self.replications addObject:repl];

       if (repl.pull) {

           [self.pullReplications addObject:repl];

       }

       [repl start];

       /*listen to all properties of all replications*/

       [repl addObserver:self forKeyPath:@"status" options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld) context:NULL];

   }


















}



Here is the crash log

Thread : Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 0x183558f48 __exceptionPreprocess
1  libobjc.A.dylib                0x198a03f80 objc_exception_throw
2  CoreFoundation                 0x1834421ec -[__NSPlaceholderArray initWithObjects:count:]
3  CoreFoundation                 0x18344dc94 +[NSArray arrayWithObjects:count:]
4  my123app                       0x1001ceb74 -[HubTouchDBService createDatabaseAndStartReplication:] (HubTouchDBService.m:134)
5  my123app                       0x10016e060 __33-[Authorization signIn:password:]_block_invoke (Authorization.m:216)
6  my123app                       0x10062433c __84-[AFHTTPSessionManager dataTaskWithHTTPMethod:URLString:parameters:success:failure:]_block_invoke74 (AFHTTPSessionManager.m:250)
7  my123app                       0x1006376fc __72-[AFURLSessionManagerTaskDelegate URLSession:task:didCompleteWithError:]_block_invoke_272 (AFURLSessionManager.m:194)
8  libdispatch.dylib              0x1992156e8 _dispatch_call_block_and_release
9  libdispatch.dylib              0x1992156a8 _dispatch_client_callout
10 libdispatch.dylib              0x19921adb0 _dispatch_main_queue_callback_4CF
11 CoreFoundation                 0x1835101f8 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
12 CoreFoundation                 0x18350e060 __CFRunLoopRun
13 CoreFoundation                 0x18343cca0 CFRunLoopRunSpecific
14 GraphicsServices               0x18e9c0088 GSEventRunModal
15 UIKit                          0x188b54ffc UIApplicationMain
16 simplyUs                       0x1000af5a0 main (main.m:14)
17 libdyld.dylib                  0x1992468b8 start


The line is is crashing on is this "[self addReplications:@[pullRepl, pushRepl]];"

Herman

Jens Alfke

unread,
Dec 1, 2015, 2:26:12 PM12/1/15
to mobile-c...@googlegroups.com
I would guess that `database` is nil. You’re not checking for a failure of the -databaseNamed:error: call.

—Jens

Herman Chan

unread,
Dec 1, 2015, 4:09:42 PM12/1/15
to Couchbase Mobile
Ah... right, thanks!

Herman
Reply all
Reply to author
Forward
0 new messages