Re: NSURL bookmark error return
Re: NSURL bookmark error return
- Subject: Re: NSURL bookmark error return
- From: Mike Abdullah <email@hidden>
- Date: Wed, 19 Dec 2012 00:11:46 +0000
On 18 Dec 2012, at 08:37, Quincey Morris <email@hidden> wrote:
> Was there a thread recently that listed a couple of Cocoa frameworks methods that mis-handle the NSError** parameter? What were those methods? The reason I ask is that the general file system documentation for dealing with bookmarks:
>
>> https://developer.apple.com/library/mac/#documentation/FileManagement/Conceptual/FileSystemProgrammingGUide/AccessingFilesandDirectories/AccessingFilesandDirectories.html#//apple_ref/doc/uid/TP40010672-CH3-SW10
>
>
> gives this code fragment:
>
>> - (NSData*)bookmarkForURL:(NSURL*)url {
>> NSError* theError = nil;
>> NSData* bookmark = [url bookmarkDataWithOptions:NSURLBookmarkCreationSuitableForBookmarkFile
>> includingResourceValuesForKeys:nil
>> relativeToURL:nil
>> error:&theError];
>> if (theError || (bookmark == nil)) {
>> // Handle any errors.
>> return nil;
>> }
>> return bookmark;
>> }
>
> which doesn't follow the rules for testing for errors. The succeeding fragment is even worse:
>
>> - (NSURL*)urlForBookmark:(NSData*)bookmark {
>> BOOL bookmarkIsStale = NO;
>> NSError* theError = nil;
>> NSURL* bookmarkURL = [NSURL URLByResolvingBookmarkData:bookmark
>> options:NSURLBookmarkResolutionWithoutUI
>> relativeToURL:nil
>> bookmarkDataIsStale:&bookmarkIsStale
>> error:&theError];
>>
>> if (bookmarkIsStale || (theError != nil)) {
>> // Handle any errors
>> return nil;
>> }
>> return bookmarkURL;
>> }
>
> since it doesn't even check the returned value.
>
> Is this a documentation error, or is the documentation explaining how to code around a frameworks deficiency?
>
> BTW the NSURL class reference documentation doesn't say anything about this. It doesn't even mention nil return values.
That sample code scares me. I wrote this recently, if it helps:
http://www.mikeabdullah.net/nsurl-bookmark-error-handling.html
_______________________________________________
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