How to Find the Source of an NSInternalInconsistencyException in an Xcode Stack Trace

This particular example doesn't give the developer much to go on. So, the answer to your question in this case is "Google it." Really, the best clue from the stack trace is the line:

[PFObject(Private) _deepSaveAsync:withCurrentUser:sessionToken:]

The line above indicates a failed save using currentUser, combined with the error message "Tried to save an object with a pointer to a new, unsaved object." should be enough to point to a probable cause.

As it turns out, this error is not uncommon and is bewildering why Parse does not fix it. It is generally caused by when your app is using anonymous Parse users and it attempts to save an object prior to the user object having been saved. Since the user object has not been saved, it has no objectId and the save of the other object fails.

The solution is to check to see if the currentUser object has an objectId, and if not, save it first before trying to write to Parse.

    // Prevent race condition for unsaved user
    // Courtesy of: http://samwize.com/2014/07/15/pitfall-with-using-anonymous-user-in-parse/
    if ([PFUser currentUser].objectId == nil) {
        [[PFUser currentUser] saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
            //do stuff later
        }];
    } else {
        //do stuff now
    }

NSInternalInconsistencyException is thrown when a code enters a state which is never supposed to happen. Usually it indicates a bug made by those who wrote it, though sometimes it is possible to cause such condition by mis-using the library (doing something against what the docs say, for instance).

In other words, it's a bug, but if you didn't write the code that throws it, it's probably not yours. From this particular stack trace, the problem has to be in Parse.

Report the bug to the original developers. A good library must never throw that, regardless if you are misusing it or not. Until they fix it, the best you can do is try to workaround it, by doing what you were trying to do in some different way. If you have the sources of that library, you could try to debug and fix the problem yourself.


When you see such kind of errors and Xcode kicks you to AppDelegate, try to put in Xcode 2 kind of breakpoints

  • Swift Error Breakpoint
  • Exception Breakpoint ...

You will find these options in the left panel on the top

Breakpoint Navigator -> + (this simbol you'll find at the bottom side) -> Swift Error Breakpoint or/and Exception Breakpoint

Hope this will help you next time

  1. enter image description here

  2. enter image description here