核心数据MOC保存会暂停执行并保存失败(无错误或崩溃) [英] core data MOC save pauses execution and fails to save (w/o error or crash)

查看:73
本文介绍了核心数据MOC保存会暂停执行并保存失败(无错误或崩溃)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近实现了核心数据并发和线程限制.我正在解决皱纹.

I have recently implemented core data concurrency and thread confinement. I am working out the wrinkles.

我有一个主MOC和一个私有MOC,它们分别以非分层方式链接到PSC.只要保存一个,它们就会合并.

I have a main MOC and a private MOC, each linked to the PSC nonhierarchically. They are merged whenever one is saved.

我遇到了MOC保存失败的问题.该应用程序不会崩溃,但是该对象不会保存,并且执行暂停(但可以恢复),并且在问题导航器中显示以下内容:

I am having an issue where a MOC save fails. The app does not crash, but the object does not save and execution pauses (but can be resumed) with the following displayed in the Issue Navigator:


如您所见,这是在私有MOC队列中执行的,这是正确的,因为这是执行暂停的行:


As you can see, this is executing in the private MOC queue, which is correct, because here's the line where execution pauses:


如您所见,我在私有MOC队列中将保存消息发送到私有MOC.


As you can see, I am sending the save message to the private MOC while in the private MOC queue.

有关如何解决此问题的任何想法?因为没有错误消息,所以我真的不知道从哪里开始.谢谢!

Any ideas on how to troubleshoot this? Because I get no error message, I really don't know where to start. Thanks!

我按照Marcus的指示替换了保存/错误代码.现在显示为:

I replaced my save/error code as Marcus instructed. It now reads:

[[self privateManagedObjectContext] performBlockAndWait:^{
    NSError *error = nil;
    if (![[self privateManagedObjectContext] save:&error]) {
        NSLog(@"ERROR SAVING MOC IN syncParseObjectLocally: %@\n%@", [error localizedDescription], [error userInfo]);
    }
    NSLog(@"%@", error);
    NSLog(@"%@\n%@", [error localizedDescription], [error userInfo]);
}];

在日志中,产生所有 null .

我没有使用iCloud.

I am not using iCloud.

当我关闭所有(objective-c-)例外断点时,执行将无缝进行(因此,我可能可以忽略此打cup,尽管更重要的是,我需要解决以下可能相关的问题:

When I turn off the all-(objective-c-)exceptions breakpoint, execution continues seamlessly (so I can probably ignore this hiccup, although more importantly, I need to address this likely related problem: core data changes don't merge)

当我在断点触发时手动输入"po error"时,日志显示:

When I enter 'po error' manually when the breakpoint triggers, the log shows:

(lldb) po error
 nil

推荐答案

您可能会遇到内部异常之一.每当存在潜在的合并冲突时,Core Data都会在内部引发异常.它可能会解决合并(这就是您所看到的),但仍会抛出.

You are probably encountering one of the internal exceptions. Core Data will throw an exception internally whenever there is a potential merge conflict. It may resolve the merge (which is what you are seeing) but it will still throw.

要对此进行测试,请将断点更改为仅在Objective-C异常而不是C ++异常上中断.如果您再也看不到中断,那就是您所看到的.

To test this, change your breakpoint to only break on Objective-C exceptions and not C++ exceptions. If you don't see the break anymore then that is what you were seeing.

还提起雷达;这种例外很烦人,如果我们获得足够的选票以进行调查,我会喜欢的.

Also, file a radar; this exception is annoying and I would love it if we got enough votes in to get it looked at.

是否有任何控制台输出?

Is there any console output?

error 变量中是否有任何值?

Is there any value in the error variable?

我知道您说您没有收到任何错误消息,但我想验证 error 变量是否为 nil 与没有有效载荷的变量.您可以在该断点处执行 po错误吗?

I know you stated that you get no error message but I want to validate that the error variable is nil vs. having no payload. Can you do a po error at that breakpoint?

此外,我会尝试将代码行更改为:

Also, I would try changing that line of code to:

[[self privateManagedObjectContext] performBlockAndWait:^{
  NSError *error = nil;
  if (![[self privateManagedObjectContext] save:&error]) {
    NSLog(@"ERROR SAVING MOC IN syncParseObjectLocally: %@\n%@", [error localizedDescription], [error userInfo]);
  }
}];

仅测试队列是否真正属于 this NSManagedObjectContext .

Just to test that the queue really belongs to this NSManagedObjectContext.

您正在使用iCloud吗?

Are you using iCloud?

如果您关闭断点,应用程序运行是否没有问题?

Does the application run with no issues if you turn breakpoints off?

当我提到 po错误时,我的意思是在遇到断点时手动输入它.

When I referred to po error I meant to do it when the breakpoint was hit and to type it in manually.

我相信调用 -performBlockAndWait:也不起作用.

I trust calling -performBlockAndWait: had no effect either.

我想知道您是否在Core Data中发现了另一个新的内部异常,并且希望我们能够隔离导致它触发的原因.

I am wondering if you have found another new internal exception being thrown in Core Data and I am hoping we can isolate what causes it to trigger.

这篇关于核心数据MOC保存会暂停执行并保存失败(无错误或崩溃)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆