Re: Returning a useful error from NSDocument's -readFromURL:...
Re: Returning a useful error from NSDocument's -readFromURL:...
- Subject: Re: Returning a useful error from NSDocument's -readFromURL:...
- From: Keith Blount <email@hidden>
- Date: Thu, 4 Mar 2010 13:53:16 -0800 (PST)
Aha, found the solution to this one at last. Many thanks to Charles, Jerry and Quincey for the help and pointers, and apologies to Quincey if I overreacted to his reply - it's been one of those weeks where the code seems to be leading to even more code rather than making progress. Anyway, in case anyone else comes across a similar problem - probably unlikely given that they are rather unique circumstances, but you never know - here is the problem and the solution.
The problem:
1. In my NSDocument subclass's -readFromURL:ofType:error: method, no matter what information I put into the NSError object, the dialogue would only ever display NSLocalizedDescriptionKey, and never NSLocalizedFailureReasonErrorKey or NSLocalizedRecoverySuggestionErrorKey.
2. If I tried to present my own error and use NSCocoaErrorDomain and NSUserCancelledError to cancel the original error, I would still get a blank dialog saying "Alert".
The solution - or rather, pilot error:
1. I recently added some third-party code to my app to provide a shortcut-recorder control (which is a great control, by the way):
http://code.google.com/p/shortcutrecorder
However, I was using an older version of their code that had an NSError category (in the SRCommon files) that returns -localizedRecoverySuggestion, -localizedFailureReason and so on (presumably the category was written before 10.4 introduced these methods), and these methods were obviously taking the place of the 10.4+ AppKit methods but make some (now) bad assumptions and return nothing - thus messing up NSError. Getting rid of this unnecessary category makes NSError work as it should again (but it looks like they have newer code I need to update to anyway).
2. In one of my document opening methods called in my NSApp delegate class, I had been calling [[NSAlert alertWithError:error] runModal] instead of [[NSDocumentController sharedDocumentController] presentError:error]. So obviously NSAlert was showing a blank error for NSUserCancelledError when -presentError:, which is what I should have used, would have ignored it.
Apologies for wasting everyone's time with what was essentially user-error, but thanks for the pointers that eventually led me to the solution after much head-butting of the desk.
All the best,
Keith
_______________________________________________
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