3lvis / Sync

JSON to Core Data and back. Swift Core Data Sync.
MIT License
2.55k stars 263 forks source link

Xcode testing does not work #256

Closed tbechtum closed 8 years ago

tbechtum commented 8 years ago

Hi,

when calling Sync.changes the following substringFromIndex exception occurs. Is it related while I am using Xcode testing? Do you have any idea?

Thanks for your help! Cheers, Thomas

    Alamofire.request(URLRequest!).validate()

        .responseString { (response) -> Void in
            // handle HTTP errors
            if let httpResponse = response.response {
                debugPrint("\(self.dynamicType).queryGoalForUser - http response status code: \(String(httpResponse.statusCode))") //NSLog("\(self.dynamicType).queryGoalForUser - http response status code: %@", String(httpResponse.statusCode))
                if httpResponse.statusCode != 200
                {
                    failure(NSError(domain: "\(self.dynamicType).queryGoalForUser", code: httpResponse.statusCode, userInfo:nil)) // causes crash , userInfo:["NSHTTPURLResponse":httpResponse.statusCode]))
                    return
                }
            }
            switch response.result {
            case .Failure(let taskError):
                // e.g. Error Domain=NSURLErrorDomain Code=-1003 "Impossibile trovare un server con il nome host specificato." when you are not connected to the Scientific Network and the URL is called
                NSLog("\(self.dynamicType).queryGoalForUser - Error: %@ (%@)", taskError.domain, taskError.description)
                failure(taskError)
                return
            default: // case .Success:
                if let webData = response.data {
                    if let output = String(data: webData, encoding: NSUTF8StringEncoding) {
                        debugPrint("\(self.dynamicType).queryGoalForUser successful - response data: \(output)") //NSLog("\(self.dynamicType).queryGoalsForUser - success response: %@", output)
                    } else {
                        NSLog("\(self.dynamicType).queryGoalForUser - success response without encoding: %@", webData)
                    }
                } else {
                    NSLog("\(self.dynamicType).queryGoalForUser - success no data")
                }
                //success()
            }
        }
        .responseJSON { response in
            let data = response.result.value as! [String : AnyObject]
            Sync.changes([data], inEntityNamed: Settings.goalDataEntityName, dataStack: self.dataStack, completion: { error in
                if let taskError = error {
                    failure(taskError)
                } else {
                    //#if DEBUG
                    self.fetchGoal(identifier.integerValue)
                    //#endif
                    success()
                }
            })
    }
}

2016-08-17 09:48:16.630 Cockpit[7573:512966] * Terminating app due to uncaught exception 'NSRangeException', reason: '* -[NSCFString substringFromIndex:]: Index 20 out of bounds; string length 19' * First throw call stack: ( 0 CoreFoundation 0x000000010619cd85 exceptionPreprocess + 165 1 libobjc.A.dylib 0x000000010656bdeb objc_exception_throw + 48 2 CoreFoundation 0x000000010619ccbd +[NSException raise:format:] + 205 3 Foundation 0x00000001038c48bd -[NSString substringFromIndex:] + 126 4 NSManagedObject_HYPPropertyMapper 0x0000000103f19230 +[NSDate(HYPPropertyMapperDateHandling) hyp_dateFromISO8601String:] + 1792 5 NSManagedObject_HYPPropertyMapper 0x0000000103f18a94 +[NSDate(HYPPropertyMapperDateHandling) hyp_dateFromDateString:] + 132 6 NSManagedObject_HYPPropertyMapper 0x0000000103f1cddb -[NSManagedObject(HYPPropertyMapperHelpers) valueForAttributeDescription:usingRemoteValue:] + 1595 7 NSManagedObject_HYPPropertyMapper 0x0000000103f19ba4 -[NSManagedObject(HYPPropertyMapper) hyp_fillWithDictionary:] + 644 8 Sync 0x00000001045c8006 _TFE4SyncCSo15NSManagedObject23sync_fillWithDictionaryfTGVs10DictionarySSPs9AnyObject6parentGSqS09dataStackC9DATAStack9DATAStack10operationsVC10DATAFilter10DATAFilter9OperationT + 294 9 Sync 0x00000001045da155 _TFZFC4Sync4Sync7changesFTGSaGVs10DictionarySSPs9AnyObject_13inEntityNamedSS9predicateGSqCSo11NSPredicate_6parentGSqCSo15NSManagedObject_9inContextCSo22NSManagedObjectContext9dataStackC9DATAStack9DATAStack10operationsVC10DATAFilter10DATAFilter9Operation10completionGSqFT5errorGSqCSo7NSErrorT_T_U_FGS1_SSPS2T + 389 10 Sync 0x00000001045d66fb _TPA_TFZFC4Sync4Sync7changesFTGSaGVs10DictionarySSPs9AnyObject13inEntityNamedSS9predicateGSqCSo11NSPredicate_6parentGSqCSo15NSManagedObject_9inContextCSo22NSManagedObjectContext9dataStackC9DATAStack9DATAStack10operationsVC10DATAFilter10DATAFilter9Operation10completionGSqFT5errorGSqCSo7NSErrorT_T_U_FGS1SSPS2T_ + 187 11 DATAFilter 0x000000010385461a TZFC10DATAFilter10DATAFilter7changesfTGSaGVs10DictionarySSPs9AnyObject13inEntityNamedSS9predicateGSqCSo11NSPredicate_10operationsVS0_9Operation15localPrimaryKeySS16remotePrimaryKeySS7contextCSo22NSManagedObjectContext8insertedFT4JSONGS1_SSPS2__T_7updatedFT4JSONGS1_SSPS2___13updatedObjectCSo15NSManagedObject_TT_ + 7194 12 Sync 0x00000001045d6134 _TZFC4Sync4Sync7changesfTGSaGVs10DictionarySSPs9AnyObject_13inEntityNamedSS9predicateGSqCSo11NSPredicate_6parentGSqCSo15NSManagedObject_9inContextCSo22NSManagedObjectContext9dataStackC9DATAStack9DATAStack10operationsVC10DATAFilter10DATAFilter9Operation10completionGSqFT5errorGSqCSo7NSError_TT_ + 2916 13 Sync 0x00000001045d9628 _TFZFC4Sync4Sync7changesFTGSaGVs10DictionarySSPs9AnyObject_13inEntityNamedSS9predicateGSqCSo11NSPredicate_9dataStackC9DATAStack9DATAStack10operationsVC10DATAFilter10DATAFilter9Operation10completionGSqFT5errorGSqCSo7NSErrorT_T_UFCSo22NSManagedObjectContextT + 424 14 Sync 0x00000001045d4a4f _TPA_TFZFC4Sync4Sync7changesFTGSaGVs10DictionarySSPs9AnyObject13inEntityNamedSS9predicateGSqCSo11NSPredicate_9dataStackC9DATAStack9DATAStack10operationsVC10DATAFilter10DATAFilter9Operation10completionGSqFT5errorGSqCSo7NSErrorT___T_UFCSo22NSManagedObjectContextT + 255 15 DATAStack 0x00000001038898e3 _TFFC9DATAStack9DATAStack29performInNewBackgroundContextFFT17backgroundContextCSo22NSManagedObjectContext_T_T_U_FTT + 67 16 DATAStack 0x0000000103889927 _TTRXFodTXFdCbdT + 39 17 CoreData 0x0000000105d2a127 developerSubmittedBlockToNSManagedObjectContextPerform + 199 18 CoreData 0x0000000105d29fee -[NSManagedObjectContext performBlockAndWait:] + 222 19 DATAStack 0x00000001038831b8 _TFC9DATAStack9DATAStack29performInNewBackgroundContextfFT17backgroundContextCSo22NSManagedObjectContext_TT + 504 20 Sync 0x00000001045d485e _TZFC4Sync4Sync7changesfTGSaGVs10DictionarySSPs9AnyObject_13inEntityNamedSS9predicateGSqCSo11NSPredicate_9dataStackC9DATAStack9DATAStack10operationsVC10DATAFilter10DATAFilter9Operation10completionGSqFT5errorGSqCSo7NSErrorTT + 414 21 Sync 0x00000001045d3c3b TZFC4Sync4Sync7changesfTGSaGVs10DictionarySSPs9AnyObject13inEntityNamedSS9dataStackC9DATAStack9DATAStack10completionGSqFT5errorGSqCSo7NSErrorT_T_ + 283 22 CockpitTests 0x00000001126f01be _TFFC12CockpitTests20SNCGoalCoreDataModel16queryGoalForUserFTSS4userCS_14SNCUserRequest7successFT_T_7failureFGSQCSo7NSError_TT_U0_FGV9Alamofire8ResponsePs9AnyObject_S2T_ + 1150 23 CockpitTests 0x00000001126eacc1 _TPATFFC12CockpitTests20SNCGoalCoreDataModel16queryGoalForUserFTSS4userCS_14SNCUserRequest7successFT_T_7failureFGSQCSo7NSError_TT_U0_FGV9Alamofire8ResponsePs9AnyObject_S2T_ + 161 24 Alamofire 0x0000000102cb13f7 _TTRXFo_oGV9Alamofire8ResponsePs9AnyObject_CSo7NSErrordTXFo_iGS0_PS1S2_dT + 151 25 Alamofire 0x0000000102cafcad _TFFFC9Alamofire7Request8responseuRxS_22ResponseSerializerTyperFT5queueGSqPSo17OS_dispatch_queue18responseSerializerx17completionHandlerFGVS_8Responsewx16SerializedObjectwx11ErrorObject_TDS0_U_FT_T_U_FTT + 797 26 Alamofire 0x0000000102cae4f4 _TPATFFFC9Alamofire7Request8responseuRxS_22ResponseSerializerTyperFT5queueGSqPSo17OS_dispatch_queue18responseSerializerx17completionHandlerFGVS_8Responsewx16SerializedObjectwx11ErrorObject_TDS0_U_FT_T_U_FTT + 164 27 Alamofire 0x0000000102c684c7 _TTRXFodTXFdCbdT__ + 39 28 libdispatch.dylib 0x0000000106fe9c89 _dispatch_call_block_and_release + 12 29 libdispatch.dylib 0x00000001070053d7 _dispatch_client_callout + 8 30 libdispatch.dylib 0x0000000106fefe5d _dispatch_main_queue_callback_4CF + 714 31 CoreFoundation 0x00000001060f60f9 CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 9 32 CoreFoundation 0x00000001060b7b99 CFRunLoopRun + 2073 33 CoreFoundation 0x00000001060b70f8 CFRunLoopRunSpecific + 488 34 Foundation 0x0000000103909a31 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 267 35 XCTest 0x0000000111fb3ffe -[XCTestCase(AsynchronousTesting) waitForExpectationsWithTimeout:handler:] + 955 36 CockpitTests 0x00000001126531de _TFC12CockpitTests16CockpitGoalTests16testGoalCoreDatafTT + 1790 37 CockpitTests 0x00000001126535d2 _TToFC12CockpitTests16CockpitGoalTests16testGoalCoreDatafTT + 34 38 CoreFoundation 0x00000001060855cc invoking_ + 140 39 CoreFoundation 0x000000010608541e -[NSInvocation invoke] + 286 40 XCTest 0x0000000111f6aef3 24-[XCTestCase invokeTest]_block_invoke_2 + 362 41 XCTest 0x0000000111f9f613 -[XCTestContext performInScope:] + 190 42 XCTest 0x0000000111f6ad78 -[XCTestCase invokeTest] + 169 43 XCTest 0x0000000111f6b3a2 -[XCTestCase performTest:] + 459 44 XCTest 0x0000000111f68cf7 -[XCTestSuite performTest:] + 396 45 XCTest 0x0000000111f68cf7 -[XCTestSuite performTest:] + 396 46 XCTest 0x0000000111f55b10 25-[XCTestDriver _runSuite]_block_invoke + 51 47 XCTest 0x0000000111f76b4c -[XCTestObservationCenter _observeTestExecutionForBlock:] + 640 48 XCTest 0x0000000111f55a55 -[XCTestDriver _runSuite] + 453 49 XCTest 0x0000000111f567d1 -[XCTestDriver _checkForTestManager] + 259 50 XCTest 0x0000000111fa0a9a _XCTestMain + 628 51 CoreFoundation 0x00000001060c22ec CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK** + 12 52 CoreFoundation 0x00000001060b7f75 CFRunLoopDoBlocks + 341 53 CoreFoundation 0x00000001060b76d2 __CFRunLoopRun + 850 54 CoreFoundation 0x00000001060b70f8 CFRunLoopRunSpecific + 488 55 GraphicsServices 0x0000000108af7ad2 GSEventRunModal + 161 56 UIKit 0x00000001046d1f09 UIApplicationMain + 171 57 Cockpit 0x0000000102472312 main + 114 58 libdyld.dylib 0x000000010703592d start + 1 59 ??? 0x0000000000000005 0x0 + 5 ) libc++abi.dylib: terminating with uncaught exception of type NSException

3lvis commented 8 years ago

@tbechtum This is related to date parsing, nothing to do with testing. Could you share an example of the JSON you're using?

tbechtum commented 8 years ago

Thanks for your immediate reply. Here is a JSON example, so I must adapt the date mapping e.g. "2015-11-09T18:05:32\", how is the best approach for this with Sync?

{\"AchievementApprovedOn\":null,\"Begin\":\"2016-01-01T00:00:00\",\"ChildId\":null,\"Created\":\"2015-11-09T18:05:32\",\"CurrentWorkflowId\":null,\"Decisions\":null,\"DepartmentTypeId\":2,\"Description\":\"Es müssen Mitarbeiter des Facility Management umgeschult werden.\",\"DescriptionDe\":null,\"DescriptionIt\":null,\"DoneComment\":null,\"DoneOn\":null,\"End\":\"2016-12-31T23:59:59\",\"GoalApprovedOn\":null,\"Id\":10343,\"IsEditable\":false,\"IsIndependent\":false,\"IsLocked\":false,\"IsYearGoal\":true,\"LastModifyStamp\":\"username\",\"ManDaysAchieved\":null,\"ManDaysPlanned\":null,\"Modified\":\"2015-11-09T18:05:32\",\"NextDeciderUsername\":\"\",\"NextDeciderFullName\":null,\"Objective\":\"Erstellung eines Maßnahmenkataloges mit Deadlines der einzelnen Maßnahmen, welche entsprechend umzusetzen sind.\",\"ObjectiveDe\":null,\"ObjectiveIt\":null,\"OwnerDepartmentId\":109952,\"OwnerDomain\":\"some\",\"OwnerHrisId\":201143,\"OwnerName\":\"Full name\",\"OwnerSubdepartmentId\":null,\"OwnerUsername\":\"username\",\"ParentId\":null,\"PointsAchieved\":null,\"PointsToAchieve\":null,\"ReferenceGoalId\":10122,\"ReferenceGoalTitle\":null,\"Status\":\"Draft\",\"Title\":\"Umsetzung von Synergien\",\"TitleDe\":null,\"TitleIt\":null,\"Year\":2016,\"OwnerImageUrl\":\"http://test.scientificnet.org/Image/Get/?domain=some&username=someone\"}

3lvis commented 8 years ago

Fixed on https://github.com/hyperoslo/Sync/releases/tag/1.11.3

Please update your Sync pod and try again :)

tbechtum commented 8 years ago

Hi Elvis!

in your documentation on github you are using e.g. "2014-03-11T19:11:00+00:00”. We are using e.g. "2015-11-09T18:05:32”. How to adapt to our format?

Thanks for your help, cheers, Thomas

On 17 Aug 2016, at 10:17, Elvis Nuñez notifications@github.com<mailto:notifications@github.com> wrote:

@tbechtumhttps://github.com/tbechtum This is related to date parsing, nothing to do with testing. Could you share an example of the JSON you're using?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/hyperoslo/Sync/issues/256#issuecomment-240344566, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AH4doftofvij61-pOqwdtxq6GrIibn1Xks5qgsN8gaJpZM4JmMCh.

3lvis commented 8 years ago

2015-11-09T18:05:32 should work too.

Have a nice day!

tbechtum commented 8 years ago

I was using 1.11.2 by pod that is the newest one I can get with cocoa pods.

Sent from my iPhone

On 17 Aug 2016, at 11:16, Elvis Nu?ez notifications@github.com<mailto:notifications@github.com> wrote:

Fixed on https://github.com/hyperoslo/Sync/releases/tag/1.11.3

Please update your Sync pod and try again :)

You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/hyperoslo/Sync/issues/256#issuecomment-240358011, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AH4doYBLxWYAhhJZ7YV7OrFkOJiXFWblks5qgtFDgaJpZM4JmMCh.

tbechtum commented 8 years ago

OK I pre-downloaded 1.11.3 and the date mapping is working now again

using pod 'Sync', :git => 'https://github.com/hyperoslo/Sync.git'

Thanks a lot, Cheers Thomas

Begin forwarded message:

From: Bechtum Thomas Thomas.Bechtum@unibz.it<mailto:Thomas.Bechtum@unibz.it> Subject: Re: [hyperoslo/Sync] Xcode testing does not work (#256) Date: 17 August 2016 at 11:31:00 GMT+2 To: hyperoslo/Sync reply@reply.github.com<mailto:reply@reply.github.com>

I was using 1.11.2 by pod that is the newest one I can get with cocoa pods.

Sent from my iPhone

On 17 Aug 2016, at 11:16, Elvis Nuñez notifications@github.com<mailto:notifications@github.com> wrote:

Fixed on https://github.com/hyperoslo/Sync/releases/tag/1.11.3

Please update your Sync pod and try again :)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/hyperoslo/Sync/issues/256#issuecomment-240358011, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AH4doYBLxWYAhhJZ7YV7OrFkOJiXFWblks5qgtFDgaJpZM4JmMCh.

Begin forwarded message:

From: Thomas Bechtum TBechtum@unibz.it<mailto:TBechtum@unibz.it> Subject: Re: [hyperoslo/Sync] Xcode testing does not work (#256) Date: 17 August 2016 at 11:16:42 GMT+2 To: hyperoslo/Sync reply@reply.github.com<mailto:reply@reply.github.com>

Hi Elvis!

in your documentation on github you are using e.g. "2014-03-11T19:11:00+00:00”. We are using e.g. "2015-11-09T18:05:32”. How to adapt to our format?

Thanks for your help, cheers, Thomas

On 17 Aug 2016, at 10:17, Elvis Nuñez notifications@github.com<mailto:notifications@github.com> wrote:

@tbechtumhttps://github.com/tbechtum This is related to date parsing, nothing to do with testing. Could you share an example of the JSON you're using?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/hyperoslo/Sync/issues/256#issuecomment-240344566, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AH4doftofvij61-pOqwdtxq6GrIibn1Xks5qgsN8gaJpZM4JmMCh.

3lvis commented 8 years ago

Now the latest one should be https://github.com/hyperoslo/Sync/releases/tag/1.11.3

Forgot to pull the trigger 😂

Added a section about supported date formats in the FAQ too

https://github.com/hyperoslo/Sync#which-date-formats-are-supported-by-sync