Commits

Jens Alfke committed c4aeedf

MyErrorUtils fixes: Renamed USE_SECURITY_API compiler flag to MYERRORUTILS_USE_SECURITY_API. Documented it in the header. Conditionalized the test cases that fail when it's not enabled.

Comments (0)

Files changed (2)

 BOOL MYMiscError( NSError **outError, NSString *messageFormat, ... )
                                 __attribute__ ((format (__NSString__, 2, 3)));
 
+/** Utilities for converting NSErrors to user-readable (but geeky) strings.
+    If your code uses Security or SSL APIs, you will probably want to #define
+    the symbol MYERRORUTILS_USE_SECURITY_API in your precompiled header, which
+    will enable the implementations of these functions to call Security API to
+    look up error messages. (This is turned off by default because it creates
+    a dependency on linking against Security.framework.)
+ */
 NSString* MYPrintableErrorCode( int code );
 NSString* MYErrorName( NSString *domain, int code );
 
 #import "CollectionUtils.h"
 #import <Foundation/Foundation.h>
 
-#if USE_SECURITY_API
+#if MYERRORUTILS_USE_SECURITY_API
 #import <Security/SecBase.h>
 #endif
 
         if (name && *name)
             result = [NSString stringWithCString: name encoding: NSMacOSRomanStringEncoding];
         else {
-#if USE_SECURITY_API
+#if MYERRORUTILS_USE_SECURITY_API
             result = (id) SecCopyErrorMessageString(code,NULL);
             if (result) {
                 [NSMakeCollectable(result) autorelease];
     CAssertEqual(err.my_nameOfCode, @"fnfErr (OSStatus -43)");
     err = [NSError errorWithDomain: NSOSStatusErrorDomain code: -25291 userInfo: nil];
     CAssertEqual(err.my_nameOfCode, @"errKCNotAvailable / errSecNotAvailable (OSStatus -25291)");
+#if MYERRORUTILS_USE_SECURITY_API
     err = [NSError errorWithDomain: NSOSStatusErrorDomain code: -25260 userInfo: nil];
     CAssertEqual(err.my_nameOfCode, @"Passphrase is required for import/export. (OSStatus -25260)");
 #endif
+#endif
     err = [NSError errorWithDomain: NSOSStatusErrorDomain code: 12345 userInfo: nil];
     CAssertEqual(err.my_nameOfCode, @"OSStatus 12345");
 
     err = [NSError errorWithDomain: @"CSSMErrorDomain" code: 2147549184u userInfo: nil];
+#if MYERRORUTILS_USE_SECURITY_API
     CAssertEqual(err.my_nameOfCode, @"CSSM_CSSM_BASE_ERROR (CSSM 2147549184)");
-
+    // If that assertion fails, you probably need to add MYError_CSSMErrorDomain.strings to your target.
+#else
+    CAssertEqual(err.my_nameOfCode, @"CSSM 2147549184");
+#endif
     err = [NSError errorWithDomain: (id)kCFErrorDomainCocoa code: 100 userInfo: nil];
     CAssertEqual(err.my_nameOfCode, @"Cocoa 100");
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.