Handling crashes in NSDocumentController reopen logic w/o subclassing?

Hi there,


Our users are experiencing crashes in the App Kit code when NSDocumentController is trying to reopen a document that the user has no longer access to.

Not sure how that happens in the wild, might be just another OS bug, however it's easy to replicate with some chown/chmod magic..


Is there a way to handle this error or display it to the user?

At the moment it's only displayed on the Console - which neither points the user to the cause of the issue nor gives our app any way to intercept and prevent App Kit from crashing.


The NSDocumentController method causing the problem/console output is:


2017-02-18 06:15:56.838164 My App [6036:900355] -[NSDocumentController reopenDocumentForURL:withContentsOfURL:display:completionHandler:] failed during state restoration. Here's the error:


Error Domain=NSCocoaErrorDomain Code=257 "The autosaved document “test.layout” could not be reopened. You don’t have permission." 
UserInfo={NSLocalizedFailureReason=You don’t have permission., NSLocalizedDescription=The autosaved document “test.layout” could not be reopened. You don’t have permission., NSLocalizedRecoverySuggestion=To view or change permissions, select the item in the Finder and choose File > Get Info., NSURL=file:/ NSUnderlyingError=0x6040000ce110 
{Error Domain=NSCocoaErrorDomain Code=257 "The file “test.layout” couldn’t be opened because you don’t have permission to view it." 
UserInfo={NSURL=file:/ NSUnderlyingError=0x6040000ce1d0 {Error Domain=NSPOSIXErrorDomain Code=13 "Permission denied"}}}}


The app crashed immediately afterwards.

We couldn't find any point to intercept this error in neither NSDocument or the app delegate.


Any hints much appreciated!


Cheers,

J