forked from jerrykrinock/CategoriesObjC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NSError+SSYAdds.h
executable file
·596 lines (495 loc) · 24.4 KB
/
NSError+SSYAdds.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
#import <Cocoa/Cocoa.h>
#import "NSError+SSYAdds.h"
// Macros for making NSErrors
/*
Quick macros to make a simple error without much thinking
First argument is int, second is NSString*.
Adds the current method name from __PRETTY_FUNCTION__ as an
object in the userInfo dictionary.
*/
#define SSYMakeError(code__,localizedDescription__) [NSError errorWithLocalizedDescription:localizedDescription__ code:code__ prettyFunction:__PRETTY_FUNCTION__]
#define SSYMakeHTTPError(code__) [NSError errorWithHTTPStatusCode:code__ prettyFunction:__PRETTY_FUNCTION__]
#define SSYAddMethodNameInError(error__) if (error__){error__=[error__ errorByAddingUserInfoObject:[NSString stringWithCString:__PRETTY_FUNCTION__ encoding:NSUTF8StringEncoding] forKey:SSYMethodNameErrorKey];}
#define SSYOverwriteMethodNameInError(error__) if (error__){error__=[error__ errorByOverwritingUserInfoObject:[NSString stringWithCString:__PRETTY_FUNCTION__ encoding:NSUTF8StringEncoding] forKey:SSYMethodNameErrorKey];}
// Macros for initializing and assigning an NSError** named error_p
/*
These are useful within functions that get an argument (NSError**)error_p
Use SSYInitErrorP to assign it to *error_p to nil at beginning of function.
(This is optional. Apple doesn't do it in their methods that take NSError**,
but I don't like the idea of leaving it unassigned.)
Then, use the next two to assign to *error_p if/when an error occurs.
Benefit: All of these macros check that error_p != NULL before assigning.
*/
#define SSYAssignErrorP(_error) if (error_p != NULL) {*error_p = _error ;}
#define SSYInitErrorP SSYAssignErrorP(nil) ;
#define SSYMakeAssignErrorP(_code,_localizedDetails) SSYAssignErrorP(SSYMakeError(_code,_localizedDetails))
#define SSYAddMethodNameToErrorP if (error_p && (*error_p != nil)) {*error_p = [*error_p errorByAddingPrettyFunction:__PRETTY_FUNCTION__] ;}
/*!
@brief Key to a string used in the userInfo dictionary of an NSError
which gives the name of the method in which the error occurred.
*/
extern NSString* const SSYMethodNameErrorKey ;
/*!
@brief Key to a localized string used in the userInfo dictionary of an NSError
suitable for use as a "title" when displaying the error to a user.
*/
extern NSString* const SSYLocalizedTitleErrorKey ;
/*!
@brief Key to an NSException in the userInfo dictionary of an NSError
which was the cause of the error.
*/
extern NSString* const SSYUnderlyingExceptionErrorKey ;
/*!
@brief Key to an NSDate which may be used to timestamp when the error occurred.
*/
extern NSString* const SSYTimestampErrorKey ;
/*!
@brief Key to the URL of a document which, when opened, will produce
an NSDocument which conforms to the NSErrorRecoveryAttempting Protocol.
@details This is useful when passing NSError objects between processes.
When presenting the error, you get it back by presenting -openRecoveryAttempterAndDisplay.
*/
extern NSString* const SSYRecoveryAttempterUrlErrorKey ;
/*!
@brief Key which you may use in error userInfo dictionaries as desired
@details A suggested use is, for example, if you are making requests
from a server, and the server throttles you and gives you a suggested
time to retry your request.
*/
extern NSString* const SSYRetryDateErrorKey ;
/*!
@brief Key to an NSNumber which indicates that the app presenting the
receiver has an -[NSApp delegate] which conforms to the
NSErrorRecoveryAttempting Protocol and should be able to recover for
the receiver.
@details This is useful when passing NSError objects between processes.
*/
extern NSString* const SSYRecoveryAttempterIsAppDelegateErrorKey ;
/*!
@brief Key to an HTTP Status Code returned by a server.
*/
extern NSString* const SSYHttpStatusCodeErrorKey ;
/*!
@brief Text which will appear at the end of a -longDescription or
-mailableLongDescription if it was truncated to meet length limitations.
*/
extern NSString* const SSYDidTruncateErrorDescriptionTrailer ;
@interface NSError (SSYAdds)
/*!
@brief Returns an error domain for the current process, which is used
by the other error-generating methods in this category.
@details For applications, this will be the main bundle identifier.
For processes that don't have an [NSBundle mainBundle], this will be the
executable name, specifically the last path component of the process'
first command-line argument.
*/
+ (NSString*)myDomain ;
+ (NSError*)errorWithLocalizedDescription:(NSString*)localizedDescription
code:(int)code
prettyFunction:(const char*)prettyFunction ;
#pragma mark * Methods for adding userInfo keys to errors already created
/*!
@brief Adds or changes a string value for string key NSLocalizedDescriptionKey to userInfo
of a copy of the receiver and returns the copy, unless the parameter is nil, then
returns the receiver.
@details This may be used to change an error's localized description.
@param newText The string value to be added for key NSLocalizedDescriptionKey
*/
- (NSError*)errorByAddingLocalizedDescription:(NSString*)newText ;
/*!
@brief Adds or overwrites a string value for string key NSLocalizedFailureReasonErrorKey
to userInfo a copy of the receiver and returns the copy, unless the parameter is nil, then
returns the receiver.
@details If you want to append a reason instead of overwriting, use
-errorByAppendingLocalizedFailureReason: instead.
@param newText The string value to be added for key NSLocalizedFailureReasonErrorKey
*/
- (NSError*)errorByAddingLocalizedFailureReason:(NSString*)newText ;
/*!
@brief Adds or appends a string value for string key NSLocalizedFailureReasonErrorKey
to userInfo a copy of the receiver and returns the copy, unless the parameter is nil, then
returns the receiver.
@details If you want to overwrite any existing failure reason instead of appending, use
-errorByAddingLocalizedFailureReason: instead.
@param newText The string value to be added for key NSLocalizedFailureReasonErrorKey
*/
- (NSError*)errorByAppendingLocalizedFailureReason:(NSString*)newText ;
/*!
@brief Adds a string value for string key SSYMethodNameErrorKey to userInfo
a copy of the receiver and returns the copy, unless the parameter is NULL, then
returns the receiver.
@details Invokes -errorByAddingUserInfoObject:forKey:, so that if such a string
key already exists, it is not overwritten. See errorByAddingUserInfoObject:forKey:.
@param newText The C string to be added for key SSYprettyFunctionErrorKey
*/
- (NSError*)errorByAddingPrettyFunction:(const char*)prettyFunction ;
/*!
@brief Adds a string value for string key NSLocalizedRecoverySuggestionErrorKey to userInfo of a copy of
the receiver and returns the copy, unless the parameter is nil, then returns the receiver.
@param newText The string value to be added for key NSLocalizedRecoverySuggestionErrorKey
*/
- (NSError*)errorByAddingLocalizedRecoverySuggestion:(NSString*)newText ;
/*!
@brief Adds a string value for string key NSRecoveryAttempterErrorKey to userInfo of a copy of
the receiver and returns the copy, unless the parameter is nil, then returns the receiver.
@details If the parameter is nil, this method is a no-op.
@param recoveryAttempter An object which conforms to the NSErrorRecoveryAttempting
informal protocol
*/
- (NSError*)errorByAddingRecoveryAttempter:(id)recoveryAttempter ;
/*!
@brief Adds a string value for string key SSYRecoveryAttempterUrlErrorKey to userInfo of a copy of
the receiver and returns the copy, unless the parameter is nil, then returns the receiver.
@details If the parameter is nil, this method is a no-op.
@param recoveryAttempter See SSYRecoveryAttempterUrlErrorKey documentation.
*/
- (NSError*)errorByAddingRecoveryAttempterUrl:(NSURL*)url ;
/*!
@brief Adds an NSNumber with -boolValue = YES for string key SSYRecoveryAttempterIsAppDelegateErrorKey
to userInfo of a copy of the receiver and returns the copy.
*/
- (NSError*)errorByAddingRecoveryAttempterIsAppDelegate ;
/*!
@brief Adds an array value for string key NSLocalizedRecoveryOptionsErrorKey to userInfo of a copy of
the receiver and returns the copy, unless the parameter is nil, then returns the receiver.
@details If the parameter is nil, this method is a no-op.
@param options The array of strings which will be added for key NSLocalizedRecoverySuggestionErrorKey
*/
- (NSError*)errorByAddingLocalizedRecoveryOptions:(NSArray*)recoveryOptions ;
/*!
@brief Adds an invocation which can be retrieved by -didRecoverInvocation to the receiver's userInfo
and returns an autoreleased copy of the receiver, unless the parameter is nil, then returns the receiver.
@details This can be used to encapsulate in the error an invocation which you can invoke after
a successful recovery occurs.
*/
- (NSError*)errorByAddingDidRecoverInvocation:(NSInvocation*)didRecoverInvocation ;
/*!
@brief Returns the invocation which was added to the receiver's userInfo by
-errorByAddingDidRecoverInvocation:, or nil if no such invocation has been added.
*/
- (NSInvocation*)didRecoverInvocation ;
/*!
@brief Adds an string which can be retrieved by -helpAnchor to the receiver's userInfo
and returns an autoreleased copy of the receiver, unless the parameter is nil, then returns the receiver.
@details This can be used to encapsulate in the error a string which your presentError:
or alertError: method can use to target a Help button.
*/
- (NSError*)errorByAddingHelpAnchor:(NSString*)helpAnchor ;
/*!
@brief Returns the string which was added to the receiver's userInfo by
-errorByAddingHelpAnchor:, or nil if no such invocation has been added.
*/
- (NSString*)helpAnchor ;
/*!
@brief Returns the object for key NSUnderlyingErrorKey in the receiver's userInfo dictionary
*/
- (NSError*)underlyingError ;
/*!
@brief Sends -underlyingError to the receiver, then sends -underlyingError
recursively to the returned underlyingError, and finally returns the last
non-nil underlying error.
*/
- (NSError*)bottomError ;
/*!
@brief Adds an error for string key NSUnderlyingErrorKey to userInfo of a copy of
the receiver and returns the copy, unless the parameter is nil, then returns the receiver.
@details Note that to make an "overlying" error, send this message to a new error
and pass the previous, underlying error.
@param underlyingError The error value to be added for key NSUnderlyingErrorKey
*/
- (NSError*)errorByAddingUnderlyingError:(NSError*)underlyingError ;
/*!
@brief Adds object for key into the userInfo of a copy of the receiver and
returns the copy, unless the parameter is nil, then returns the receiver.
@details If proposedKey already has a value in the receiver's userInfo,
then the description (in case it is not a string) of the proposedKey is
extracted and a sequence number is appended to make a unique key, and the
existing value is set under this new key. If a value already exists for
that key, then it too is changed to have a key constructed with a higher
sequence number.
Example:
Before this method is invoked, userInfo has:
* key="Foo" object="Fred"
* key="Foo-01 object="Barney"
Now say we invoke this method with key="Foo" and object="Wilma".
The result in userInfo will be:
* key="Foo" object="Wilma"
* key="Foo-01 object="Fred"
* key="Foo-02 object="Barney"
If the 'object' parameter is nil, this method is a no-op.
@param object of the pair to be added
@param key of the pair to be added
*/
- (NSError*)errorByAddingUserInfoObject:(id)object
forKey:(NSString*)proposedKey ;
/*!
@brief Same as errorByAddingUserInfoObject:forKey: except overwrites
any existing key instead of modifying proposedKey to be unique
*/
- (NSError*)errorByOverwritingUserInfoObject:(id)object
forKey:(NSString*)key ;
/*!
@brief Adds keys and values explaining a given exception to the userInfo
of a copy of the receiver and returns the copy, unless the parameter is nil, then returns the receiver.
@param exception The exception whose info is to be added
*/
- (NSError*)errorByAddingUnderlyingException:(NSException*)exception ;
/*!
@brief Adds a value for string key SSYLocalizedTitleErrorKey to userInfo of a copy of
the receiver and returns the copy, unless the parameter is nil, then returns the receiver.
@param title The string value to be added for key SSYLocalizedTitleErrorKey
*/
- (NSError*)errorByAddingLocalizedTitle:(NSString*)title ;
/*!
@brief Returns a replica of the receiver, except that if
the receiver's userInfo contains NSRecoveryAttempterErrorKey,
the returned replica will not.
@details This is useful prior to archiving an error which will be later
presented in a context where its indicated recovery is not possible.
Note that it does not remove the SSYRecoveryAttempterUrlErrorKey, or the
NSRecoveryOptionsErrorKey, or the SSYRecoveryAttempterIsAppDelegateErrorKey,
because they should work, and will be tried if NSRecoveryAttempterErrorKey
is removed.
*/
- (NSError*)errorByRemovingRecoveryAttempter ;
/*!
@brief Returns the string value in the receiver's userInfo dictionary
for the key SSYLocalizedTitleErrorKey, or if that is nil, the first
line of text from the receiver's localizedDescripiton, or if that is nil,
nil.
*/
- (NSString*)localizedTitle ;
/*!
@brief Returns a readable multiline description which contains
the -descriptionForDialog of the receiver and all of its
antecedent underlying errors.
*/
- (NSString*)localizedDeepDescription ;
- (NSError*)errorByAddingTimestamp:(NSDate*)date ;
- (NSError*)errorByAddingTimestampNow ;
- (NSDate*)timestamp ;
/*!
@brief Adds a special key/value pair to the userInfo of a copy of
the receiver and returns the copy, unless the parameter is nil, then returns the
receiver. The special key/value pair causes
the returned error to return NO when sent -shouldShowSupportEmailButton.
*/
- (NSError*)errorByAddingDontShowSupportEmailButton ;
/*!
@brief Returns NO if the receiver has the special key/value pair added by
-errorByAddingDontShowSupportEmailButton. Otherwise, returns YES.
*/
- (BOOL)shouldShowSupportEmailButton ;
/*!
@brief Adds a special key/value pair to the userInfo of a copy of
the receiver and returns the copy, unless the parameter is nil, then returns
the receiver. The special key/value pair causes
the returned error to return YES when sent -isOnlyInformational.
*/
- (NSError*)errorByAddingIsOnlyInformational ;
/*!
@brief If the receiver's -userInfo contains a value for key @"Path",
and if this path begins with @"/Volumes/SomeVolume/", and if SomeVolume
is apparently not mounted, returns a replica of the receiver with a
localized recovery suggestion to mount SomeVolume added; otherwise,
returns the receiver.
*/
- (NSError*)maybeAddMountVolumeRecoverySuggestion ;
/*!
@brief Adds a "Backtrace" key to the userInfo of a copy of
the receiver and returns the copy. The value of the key is
the current stack backtrace, provided by SSYDebugBacktrace().
*/
- (NSError*)errorByAddingBacktrace ;
/*!
@brief Returns YES if the receiver has the special key/value pair added by
-errorByAddingIsOnlyInformational. Otherwise, returns NO.
*/
- (BOOL)isOnlyInformational ;
/*!
@brief Adds a special key/value pair to the userInfo of a copy of
the receiver and returns the copy, unless the parameter is nil, then returns
the receiver. The special key/value pair causes
the returned error to return YES when sent -isLogged.
*/
- (NSError*)errorByAddingIsLogged ;
/*!
@brief Returns YES if the receiver has the special key/value pair added by
-errorByAddingIsLogged Otherwise, returns NO.
*/
- (BOOL)isLogged ;
/*!
@brief An improved -description, which gives a detailed, multi-line
description of the error, including all keys and values in the userInfo
dictionary.
@details Individual keys and values in the userInfo dictionary, as well
as the entire description of the userInfo, are truncated in the middle
to reasonable lengths if they are unreasonably long.
If this category were instead a class, I would instead override
-description with the implementation of this method.
This method will call itself
in the event that one of the values in the userInfo dictionary is itself
an NSError, and this should occur when one of the keys is
NSUnderlyingErrorKey. The lines in the output string will each
be indented by several spaces.
To prevent runaway, the keys in the userInfo, values in userInfo, and
length of the entire output are truncated to non-ridiculous lengths.
If the result is truncated, it will end in SSYDidTruncateErrorDescriptionTrailer.
*/
- (NSString*)longDescription ;
/*!
@brief Same as -longDescription, except the truncation limits are
lower, appropriate to fit in the body of an email message.
*/
- (NSString*)mailableLongDescription ;
/*!
@brief Returns a localized description appropriate for displaying the essence
of the receiver to the user in a dialog.
@details Begins with the receiver's localizedDescription,
Then if there is a localizedFailureReason, appends two line feeds, and a localized
label followed by the value of localizedFailureReason.
Then if there is a localizedRecoverySuggestion, appends two line feeds, and a localized
label followed by the value of localizedRecoverySuggestion.
Then if the class object NSError responds to selector additionalKeysInDescriptionForDialog
(which must return an array of strings), will iterate through each of these
strings and, for each which has a value in the receiver's userInfo dictionary,
appends two line feeds, and a localized label for the key followed by its value
from userInfo.
*/
- (NSString*)descriptionForDialog ;
/*!
@brief Returns a keyed archive of the receiver, after replacing any unserializable
objects in its -userInfo by their -description.
@details NSError conforms to NSCoding, but if you try and archive one whose
userInfo dictionary contains an object which does not, you'll get an exception.
This method iterates recursively through the userInfo dictionary, replacing any object
which is not serializable by its -description, then as a convenience, applies
-[NSKeyedArchiver archivedDataWithRootObject] and returns the result.
To-do: Could relax the 'serializable' requirement to 'encodeable'.
See NSObject+DeepCopy.
*/
- (NSData*)keyedArchive ;
/*!
@brief Returns the error code of the error which is at
the bottom of the receiver's stack of underlying errors.
@details If the receiver has nil underlyingError, returns
the error code of the receiver.
*/
- (NSInteger)mostUnderlyingErrorCode ;
/*!
@brief Returns a set of numbers whose intValues are the -code of the receiver and
the codes of all underlying errors, but only if the relevant error's domain is
equal to a given domain, unless domain is nil in which case it's the codes of
all underlying errors.
*/
- (NSSet*)allInvolvedCodesInDomain:(NSString*)domain ;
/*!
@brief Returns whether the receiver or any of its underlying errors is in a given domain
and has a code in a given set, unless the given domain is nil then it returns whether or
not the receiver or any of its underlying errors simply has a code in a given set.
*/
- (BOOL)involvesOneOfCodesInSet:(NSSet*)targetCodes
domain:(NSString*)domain ;
/*!
@brief Returns whether the receiver or any of its underlying errors has a code
in a given set.
*/
- (BOOL)involvesOneOfCodesInSet:(NSSet*)targetCodes ;
/*!
@brief Returns whether the receiver or any of its underlying errors is in +myDomain
and has a code in a given set.
*/
- (BOOL)involvesOneOfMyCodesInSet:(NSSet*)targetCodes ;
/*!
@brief Returns whether the receiver or any of its underlying errors is in a given domain
and has a given code, unless the given domain is nil then it returns whether or
not the receiver or any of its underlying errors simply has the given code.
*/
- (BOOL)involvesCode:(NSInteger)code
domain:(NSString*)domain ;
/*!
@brief Returns whether the receiver or any of its underlying errors has a given code.
*/
- (BOOL)involvesCode:(NSInteger)code ;
/*!
@brief Returns whether the receiver or any of its underlying errors is in +myDomain
and has a given code.
*/
- (BOOL)involvesMyDomainAndCode:(NSInteger)code ;
/*!
@brief Returns NO if the receiver's domain is NSCocoaErrorDomain and code
is NSFileReadNoSuchFileError, YES otherwise
@details NSFileReadNoSuchFileError in NSCocoaErrorDomain is returned by
-[NSFileManager contentsOfDirectoryAtPath:error:] if the given path does
not exist. Use this method to process only other errors, like this
• if ([error isNotFileNotFoundError]) {
• // This is a serious error, do something about it
• …
• }
*/
- (BOOL)isNotFileNotFoundError ;
/*!
@brief Returns whether or not the receiver has either a recovery
attempter or a recovery URL, and has at least one recovery option.
@details A replacement for -localizedRecoveryOptions which also checks the
availability of a recovery attempter and that -localizedRecoveryOptions
is not empty. This method differs from -localizedRecoveryOptions in that it
will return nil if the receiver's info dictionary does not include either
a recoveryAttempter or recoveryAttempterUrl or recoveryAttempterIsAppDelegate
!= YES, or if the count of -localizedRecoveryOptions is 0.
Generally, if this method returns nil, when displaying the error, you should
display only the usual "OK" button instead of recovery options.
When checking for the attempters, this method only checks to see if either
of the three values are non-nil/YES. It does not test whether or not the
recoveryAttempter or app delegate conforms to NSErrorRecoveryAttempting
Protocol, nor test if there is even a file at the path specified by the
recoveryAttempterUrl.
The idea is that, when displaying the error, you assume that it is
well-formed, and not worry about actual performance until after and *if*
the user clicks a recovery option.
*/
- (BOOL)isRecoverable ;
/*!
@brief Returns the deepest of either the receiver, or one of the underlying
errors in its underlyingError lineage, which is recoverable, or nil if none
of these errors are recoverable.
@details The idea behind this is that the deepest underlying error is the
root cause from which you cant to recover. You should use this method in
*both* your error presentation method(s) *and* in your
attemptRecoveryFromError::::: and attemptRecoveryFromError:: method(s).
(If you only use it in presentation or only in attempting recovery, you
might miss recovery options, get the wrong recovery option performed, etc.)
Recoverability is determined by -isRecoverable. If none of the
constituent errors are recoverable, returns nil.
*/
- (NSError*)deepestRecoverableError ;
/*!
@brief A replacement for -recoveryAttempter which also uses the receiver's
recovery attempter URL, if any.
@details First, this method returns the receiver's -recoveryAttempter, if any.
Second, if that is nil, and if the receiver has a -recoveryAttempterUrl, it returns
nil if the given recoveryOption is not NSAlertAlternateReturn (*), and otherwise asks
the shared document controller to open the document specified by the
recoveryAttempterUrl and returns whatever results (which may be nil).
Third, if the receiver's -recoveryAttempterUrl is nil, and if the receiver's
-userInfo has a value for SSYRecoveryAttempterIsAppDelegateErrorKey whose
-boolValue is YES, it returns -[NSApp delegate].
(*) The recoveryOption value of NSAlertAlternateReturn is assumed to mean "Cancel".
Now, I don't like the idea of peeking into the recoveryOption in this
method. It kind of breaks encapsulation. But otherwise we'd open
a document just to have it tell us that the recovery was cancelled,
which would look stupid and be stupid.
@param error_p Pointer which will, upon return, if the receiver does not
have a recovery attempter, does have a recovery attempter URL, and if an
attempt was made to open the document specified by that recovery attempter
URL, and the attempt failed, and if error_p is not NULL, point to
an NSError (yes, a*nother* NSError) describing the problem with opening
the document. Note that 'nil' is a legitimate return value for this
method, andthe fact that this method returns nil does
not necessarily mean that error_p will point to an error.
@result The receiver's recovery attempter, or the NSDocument produced by
opening the receiver's recoveryAttempterUrl, or nil if neither is available.
*/
- (id)openRecoveryAttempterForRecoveryOption:(NSInteger)recoveryOption
error_p:(NSError**)error_p ;
@end