如何在Xcode堆栈跟踪中查找NSInternalInconsistencyException的源代码

Ich*_*aki 8 debugging xcode objective-c stack-trace ios

我正在使用Objective-C中的iPhone应用程序(使用Xcode 6.1.1和Parse),我只是觉得这个很神秘NSInternalInconsistencyException:

Caught "NSInternalInconsistencyException" with reason "Tried to save an object with a pointer to a new, unsaved object.":

所以我对Stack Overflow社区的问题是:

有人如何读取此堆栈跟踪以查找问题的实际来源?我没有在此堆栈跟踪中的任何位置看到任何可识别的文件名,方法调用或行号.

或者,如果不是简单地读取堆栈跟踪并且涉及其他技术,那么开发人员应该采取哪些适当的下一步来追踪此类错误的来源?

这是输出到我的控制台的完整堆栈跟踪:

2015-07-18 02:01:17.596 testapp[1276:60b] [Error]: Caught "NSInternalInconsistencyException" with reason "Tried to save an object with a pointer to a new, unsaved object.":
(
    0   CoreFoundation                      0x2f547f9b  + 154
    1   libobjc.A.dylib                     0x39c94ccf objc_exception_throw + 38
    2   CoreFoundation                      0x2f547ec5  + 0
    3   testapp                             0x00205a29 -[PFObject(Private) resolveLocalId] + 384
    4   testapp                             0x00233d6d __32-[PFRESTCommand resolveLocalIds]_block_invoke + 24
    5   testapp                             0x00233783 +[PFRESTCommand forEachLocalIdIn:doBlock:] + 642
    6   testapp                             0x00233ba7 __42+[PFRESTCommand forEachLocalIdIn:doBlock:]_block_invoke + 62
    7   CoreFoundation                      0x2f484043  + 98
    8   CoreFoundation                      0x2f483f67  + 162
    9   testapp                             0x0023367f +[PFRESTCommand forEachLocalIdIn:doBlock:] + 382
    10  testapp                             0x00233ba7 __42+[PFRESTCommand forEachLocalIdIn:doBlock:]_block_invoke + 62
    11  CoreFoundation                      0x2f484043  + 98
    12  CoreFoundation                      0x2f483f67  + 162
    13  testapp                             0x0023367f +[PFRESTCommand forEachLocalIdIn:doBlock:] + 382
    14  testapp                             0x0023373f +[PFRESTCommand forEachLocalIdIn:doBlock:] + 574
    15  testapp                             0x00233ba7 __42+[PFRESTCommand forEachLocalIdIn:doBlock:]_block_invoke + 62
    16  CoreFoundation                      0x2f484043  + 98
    17  CoreFoundation                      0x2f483f67  + 162
    18  testapp                             0x0023367f +[PFRESTCommand forEachLocalIdIn:doBlock:] + 382
    19  testapp                             0x00233ca3 -[PFRESTCommand forEachLocalId:] + 162
    20  testapp                             0x00233d3f -[PFRESTCommand resolveLocalIds] + 34
    21  testapp                             0x0023ee2f -[PFRESTCommandRunner _runCommandAsync:withCancellationToken:] + 110
    22  testapp                             0x0023e8c7 -[PFRESTCommandRunner runCommandAsync:withOptions:cancellationToken:] + 174
    23  testapp                             0x0023e7d7 -[PFRESTCommandRunner runCommandInBackground:inOperation:] + 42
    24  testapp                             0x00203667 __65+[PFObject(Private) _deepSaveAsync:withCurrentUser:sessionToken:]_block_invoke_3 + 766
    25  testapp                             0x002854b3 __55-[BFTask continueWithExecutor:block:cancellationToken:]_block_invoke_2 + 214
    26  libdispatch.dylib                   0x3a17c833  + 10
    27  libdispatch.dylib                   0x3a183ad7  + 222
    28  libdispatch.dylib                   0x3a183d29  + 56
    29  libsystem_pthread.dylib             0x3a2bebd3 _pthread_wqthread + 298
    30  libsystem_pthread.dylib             0x3a2bea98 start_wqthread + 8
).

我感谢您提供给我的任何帮助和见解.

pic*_*ano 5

这个特定的示例并没有给开发人员提供太多的帮助。因此,在这种情况下,您的问题的答案是“Google it”。实际上,堆栈跟踪中最好的线索是这一行:

[PFObject(Private) _deepSaveAsync:withCurrentUser:sessionToken:]
Run Code Online (Sandbox Code Playgroud)

上面的行表示使用 保存失败currentUser,并显示错误消息“尝试使用指向新的未保存对象的指针来保存对象”。应该足以指出可能的原因。

事实证明,这个错误并不罕见,并且令人困惑的是为什么 Parse 不修复它。这通常是由于您的应用程序使用匿名 Parse 用户并且它尝试在保存用户对象之前保存对象而引起的。由于用户对象尚未保存,因此它没有,objectId并且其他对象的保存失败。

解决方案是检查currentUser对象是否有objectId,如果没有,则在尝试写入 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
    }
Run Code Online (Sandbox Code Playgroud)