Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors/exceptions should be propagated to avoid crashes #224

Closed
Jonge opened this issue Jun 1, 2016 · 5 comments
Closed

Errors/exceptions should be propagated to avoid crashes #224

Jonge opened this issue Jun 1, 2016 · 5 comments
Assignees

Comments

@Jonge
Copy link

Jonge commented Jun 1, 2016

There are lines like:

    guard let copiedObject = context.sync_safeObject(entityName, localPrimaryKey: localPrimaryKey, parent: nil, parentRelationshipName: nil) else { fatalError("Couldn't fetch a safe object from entityName: \(entityName) localPrimaryKey: \(localPrimaryKey)") }

and:

    do {
        let objects = try executeFetchRequest(request)
        return objects.first as? NSManagedObject
      } catch {
        fatalError("Failed to fetch request for entityName: \(entityName), predicate: \(request.predicate)")
      }

(and in some other places) that can (and do) cause crashes. Instead, an error should be caught/produced and propagated all the way through to the changes methods in Sync class, so that the developer can handle them instead.

By the way, the latest release (1.9.0) is super stable so far. These crashes are VERY rare (less than 0.5% of users). So thanks a lot, you have done a great job! 👍

@3lvis
Copy link
Owner

3lvis commented Jun 1, 2016

Hi @Jonge,

Do you have any crashes in specific that we should look at? Usually is hard to recover from Core Data failures that's why the default for some cases it has been to just crash, but there's also the chance that the crashes are our fault and would be great to reproduce them to provide a solution.

@Jonge
Copy link
Author

Jonge commented Jun 2, 2016

I have some crash logs, but I'm pretty sure it is my fault, as I am not yet cancelling Sync operations. So there might be an issue when parsing a JSON with an object that meanwhile gets deleted, but not 100 % sure.

Sorry those are a bit mangled, this is how i got it from HockeyApp.

1   Sync                                 0x00000001010b04a4 _TTSf4g_n___TFE4SyncCSo15NSManagedObject18sync_copyInContextfCSo22NSManagedObjectContextS0_ (NSManagedObject+Sync.swift:20)
2   Sync                                 0x00000001010afb08 _TToFE4SyncCSo15NSManagedObject18sync_copyInContextfCSo22NSManagedObjectContextS0_ (NSManagedObject+Sync.swift:0)
3   Sync                                 0x00000001010baab4 _TFZFC4Sync4Sync7changesFTGSaGVs10DictionarySSPs9AnyObject___13inEntityNamedSS6parentCSo15NSManagedObject9dataStackC9DATAStack9DATAStack10completionGSqFT5errorGSqCSo7NSError__T___T_U_FCSo22NSManagedObjectContextT_ (Sync.swift:159)
4   Sync                                 0x00000001010b942c _TPA__TFZFC4Sync4Sync7changesFTGSaGVs10DictionarySSPs9AnyObject___13inEntityNamedSS6parentCSo15NSManagedObject9dataStackC9DATAStack9DATAStack10completionGSqFT5errorGSqCSo7NSError__T___T_U_FCSo22NSManagedObjectContextT_ (Sync.swift:0)
5   CoreData                             0x000000018426d08c developerSubmittedBlockToNSManagedObjectContextPerform + 192
1   Sync                                 0x00000001010a578c _TTSf4gs_g_g_g_n___TFE4SyncCSo22NSManagedObjectContext15sync_safeObjectfTSS15localPrimaryKeyGSqPs9AnyObject__6parentGSqCSo15NSManagedObject_22parentRelationshipNameGSqSS__GSqS2__ (NSManagedObjectContext+Sync.swift:20)
2   Sync                                 0x00000001010a5058 _TToFE4SyncCSo22NSManagedObjectContext15sync_safeObjectfTSS15localPrimaryKeyGSqPs9AnyObject__6parentGSqCSo15NSManagedObject_22parentRelationshipNameGSqSS__GSqS2__ (NSManagedObjectContext+Sync.swift:0)
3   Sync                                 0x00000001010a0200 _TTSf4g_n___TFE4SyncCSo15NSManagedObject18sync_copyInContextfCSo22NSManagedObjectContextS0_ (NSManagedObject+Sync.swift:20)
4   Sync                                 0x000000010109fb08 _TToFE4SyncCSo15NSManagedObject18sync_copyInContextfCSo22NSManagedObjectContextS0_ (NSManagedObject+Sync.swift:0)
5   Sync                                 0x00000001010aaab4 _TFZFC4Sync4Sync7changesFTGSaGVs10DictionarySSPs9AnyObject___13inEntityNamedSS6parentCSo15NSManagedObject9dataStackC9DATAStack9DATAStack10completionGSqFT5errorGSqCSo7NSError__T___T_U_FCSo22NSManagedObjectContextT_ (Sync.swift:159)
6   Sync                                 0x00000001010a942c _TPA__TFZFC4Sync4Sync7changesFTGSaGVs10DictionarySSPs9AnyObject___13inEntityNamedSS6parentCSo15NSManagedObject9dataStackC9DATAStack9DATAStack10completionGSqFT5errorGSqCSo7NSError__T___T_U_FCSo22NSManagedObjectContextT_ (Sync.swift:0)
7   CoreData                             0x000000018549508c developerSubmittedBlockToNSManagedObjectContextPerform + 192

Also, I am getting these crashes in DATAFilter, which I would say are not my fault, but again not sure. Didn't yet have the time to dig into it. Also happens much more often than the ones above.

Application Specific Information:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSDictionary initWithObjects:forKeys:]: count of objects (6) differs from count of keys (2)'

4   DATAFilter                           0x0000000100ae1404 +[DATAFilter changes:inEntityNamed:predicate:operations:localPrimaryKey:remotePrimaryKey:context:inserted:updated:] (DATAFilter.m:43)
5   Sync                                 0x0000000101011928 _TTSf4g_gs_g_g_g_g_n_g_d___TZFC4Sync4Sync7changesfTGSaGVs10DictionarySSPs9AnyObject___13inEntityNamedSS9predicateGSqCSo11NSPredicate_6parentGSqCSo15NSManagedObject_9inContextCSo22NSManagedObjectContext9dataStackC9DATAStack9DATAStack10operationsVSC19DATAFilterOperation10completionGSqFT5errorGSqCSo7NSError__T___T_ (Sync.swift:219)
6   Sync                                 0x000000010100fd5c _TZFC4Sync4Sync7changesfTGSaGVs10DictionarySSPs9AnyObject___13inEntityNamedSS9predicateGSqCSo11NSPredicate_6parentGSqCSo15NSManagedObject_9inContextCSo22NSManagedObjectContext9dataStackC9DATAStack9DATAStack10operationsVSC19DATAFilterOperation10completionGSqFT5errorGSqCSo7NSError__T___T_ (Sync.swift:191)
7   Sync                                 0x000000010100a880 _TTSf4g_g_g_g_n_n___TFE4SyncCSo15NSManagedObject23sync_toManyRelationshipfTCSo25NSRelationshipDescription10dictionaryGVs10DictionarySSPs9AnyObject__6parentGSqS0__9dataStackC9DATAStack9DATAStack10operationsVSC19DATAFilterOperation_T_ (NSManagedObject+Sync.swift:165)
8   Sync                                 0x0000000101007e3c _TToFE4SyncCSo15NSManagedObject23sync_toManyRelationshipfTCSo25NSRelationshipDescription10dictionaryGVs10DictionarySSPs9AnyObject__6parentGSqS0__9dataStackC9DATAStack9DATAStack10operationsVSC19DATAFilterOperation_T_ (NSManagedObject+Sync.swift:0)
9   Sync                                 0x000000010100cc34 _TTSf4g_g_g_g_g_n___TFFE4SyncCSo15NSManagedObject23sync_fillWithDictionaryFTGVs10DictionarySSPs9AnyObject__6parentGSqS0__9dataStackC9DATAStack9DATAStack10operationsVSC19DATAFilterOperation_T_U_FCSo25NSRelationshipDescriptionT_ (NSManagedObject+Sync.swift:46)
10  Sync                                 0x00000001010088cc _TTSf4g_g_g_n_n___TFE4SyncCSo15NSManagedObject23sync_fillWithDictionaryfTGVs10DictionarySSPs9AnyObject__6parentGSqS0__9dataStackC9DATAStack9DATAStack10operationsVSC19DATAFilterOperation_T_ (NSManagedObject+Sync.swift:0)
11  Sync                                 0x0000000101007c34 _TToFE4SyncCSo15NSManagedObject23sync_fillWithDictionaryfTGVs10DictionarySSPs9AnyObject__6parentGSqS0__9dataStackC9DATAStack9DATAStack10operationsVSC19DATAFilterOperation_T_ (NSManagedObject+Sync.swift:0)
12  Sync                                 0x0000000101013260 _TFZFC4Sync4Sync7changesFTGSaGVs10DictionarySSPs9AnyObject___13inEntityNamedSS9predicateGSqCSo11NSPredicate_6parentGSqCSo15NSManagedObject_9inContextCSo22NSManagedObjectContext9dataStackC9DATAStack9DATAStack10operationsVSC19DATAFilterOperation10completionGSqFT5errorGSqCSo7NSError__T___T_U_FGSQGS1_CSo8NSObjectPS2____T_ (Sync.swift:215)
13  Sync                                 0x0000000101012144 _TPA__TFZFC4Sync4Sync7changesFTGSaGVs10DictionarySSPs9AnyObject___13inEntityNamedSS9predicateGSqCSo11NSPredicate_6parentGSqCSo15NSManagedObject_9inContextCSo22NSManagedObjectContext9dataStackC9DATAStack9DATAStack10operationsVSC19DATAFilterOperation10completionGSqFT5errorGSqCSo7NSError__T___T_U_FGSQGS1_CSo8NSObjectPS2____T_ (Sync.swift:0)
14  Sync                                 0x000000010101337c _TTRXFo_oGSQGVs10DictionaryCSo8NSObjectPs9AnyObject____dT__XFdCb_dGSQCSo12NSDictionary__dT__ (Sync.swift:0)
15  DATAFilter                           0x0000000100ae16b8 +[DATAFilter changes:inEntityNamed:predicate:operations:localPrimaryKey:remotePrimaryKey:context:inserted:updated:] (DATAFilter.m:72)
16  Sync                                 0x0000000101011928 _TTSf4g_gs_g_g_g_g_n_g_d___TZFC4Sync4Sync7changesfTGSaGVs10DictionarySSPs9AnyObject___13inEntityNamedSS9predicateGSqCSo11NSPredicate_6parentGSqCSo15NSManagedObject_9inContextCSo22NSManagedObjectContext9dataStackC9DATAStack9DATAStack10operationsVSC19DATAFilterOperation10completionGSqFT5errorGSqCSo7NSError__T___T_ (Sync.swift:219)
17  Sync                                 0x0000000101012fe0 _TFZFC4Sync4Sync7changesFTGSaGVs10DictionarySSPs9AnyObject___13inEntityNamedSS6parentCSo15NSManagedObject9dataStackC9DATAStack9DATAStack10completionGSqFT5errorGSqCSo7NSError__T___T_U_FCSo22NSManagedObjectContextT_ (Sync.swift:168)
18  Sync                                 0x000000010101142c _TPA__TFZFC4Sync4Sync7changesFTGSaGVs10DictionarySSPs9AnyObject___13inEntityNamedSS6parentCSo15NSManagedObject9dataStackC9DATAStack9DATAStack10completionGSqFT5errorGSqCSo7NSError__T___T_U_FCSo22NSManagedObjectContextT_ (Sync.swift:0)
19  CoreData                             0x00000001837d508c developerSubmittedBlockToNSManagedObjectContextPerform + 192

I might try to do a bit of debugging to make sure that I am doing something wrong.

Thank you so far!

@Jonge
Copy link
Author

Jonge commented Jun 23, 2016

Hi again.

The only crash I really care about now is the last one in DATAFilter. From my observation, it happens when the primary keys are not unique (e.g. when the JSON contains multiple primary keys of equal values).

While I agree that it should not really happen if everything is correctly set up, it can't be guaranteed that the output from JSON is valid.

I think in this case, the error could be easily caught (if changes.count != remoteObjectIDs.count on line 42 in DATAFilter.m) and probably just throw an error.

I'm pretty busy right now, but I can try to find some time for a pull request if needed.

@3lvis
Copy link
Owner

3lvis commented Jun 23, 2016

Thanks @Jonge,

That's pretty useful. I'll add an issue on that repo to follow up later.

🙏

@3lvis
Copy link
Owner

3lvis commented Nov 30, 2016

Most errors should be propagated now, if you have any other suggestions please let me know.

@3lvis 3lvis closed this as completed Nov 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants