Re: NSDocument window opens - even if the document didn't read properly.
Re: NSDocument window opens - even if the document didn't read properly.
- Subject: Re: NSDocument window opens - even if the document didn't read properly.
- From: Quincey Morris <email@hidden>
- Date: Sun, 29 Jul 2012 12:15:17 -0700
On Jul 29, 2012, at 10:53 , Pascal Harris <email@hidden> wrote:
> 2. If the document fails to open then I want to copy it to a new location, with a new extension (see above). This fails. I can't think why!
On Jul 29, 2012, at 11:47 , Pascal Harris <email@hidden> wrote:
> Good point - I've now fixed this. That still doesn't explain why the window stays open though. When I fix this problem, it doesn't provide an error message to the user either. Perhaps this is connected to the reason that the window opens anyway, even if the data can't be read.
The implication of your two statements here (no error message, no creation of the copy) is that 'loadTextViewWithInitialData' is in fact returning YES.
Returning NO from 'readFromData:' really does cause NSDocumentController to display an alert (except when the returned error is NSCocoaErrorDomain/NSUserCancelledError, which is a standard way of preventing it from complaining). Since you've already acknowledged that the code you posted is not the actual code, we have to assume you have a code path through your real code that's returning YES.
> NSMutableDictionary *errorDetail = [NSMutableDictionary dictionary];
> [errorDetail setValue:@"This file is corrupted and could not be read." forKey:NSLocalizedDescriptionKey];
>
> *outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:1 userInfo:
> errorDetail];
You should always check that 'outError' isn't NULL before dereferencing it. The NSError** outError pattern doesn't require outError to be non-NULL. I suspect that NSDocumentController never passes NULL, but it would be best to get used to avoiding the assumption.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden