@@ -207,26 +207,32 @@ - (id)mmm_stripNSNull {
207
207
@implementation NSError (MMMTemple)
208
208
209
209
- (NSString *)mmm_description {
210
-
211
210
NSMutableString *result = [[NSMutableString alloc ] init ];
212
-
213
211
NSError *e = self;
214
212
// Note that Swift errors returning `nil` for underlyingError might end up with NSNull there.
215
213
while (e && ![e isKindOfClass: [NSNull class ]]) {
216
-
217
214
if ([result length ] > 0 )
218
215
[result appendString: @" > " ];
216
+ [result appendString: [e mmm_nonRecursiveDescription ]];
217
+ e = e.userInfo [NSUnderlyingErrorKey ];
218
+ }
219
+ return result;
220
+ }
219
221
222
+ - (NSString *)mmm_nonRecursiveDescription {
223
+ if (self.class == NSClassFromString (@" __SwiftNativeNSError" )) {
224
+ // Treating underlying Swift errors as NSError is normally useless and it's better to fall back to their descriptions instead.
225
+ // (I could check for `self.class != NSError.class` here to make it less dependent on the actual system class name,
226
+ // but that would include rare subclasses like `NSURLError`; I could also check for "Swift" in the class name, but that still
227
+ // would not guarantee to cover future changes in the standard library anyway.)
228
+ return [self description ];
229
+ } else {
220
230
// Treating the -1 error code as "other" kind of error, where only the message matters for diagnostics.
221
- if (e .code != -1 )
222
- [result appendString: [NSString stringWithFormat: @" %@ (%@ #%ld )" , e .localizedDescription, e .domain, (long )e .code] ];
231
+ if (self .code != -1 )
232
+ return [NSString stringWithFormat: @" %@ (%@ #%ld )" , self .localizedDescription, self .domain, (long )self .code];
223
233
else
224
- [result appendString: [NSString stringWithFormat: @" %@ (%@ )" , e.localizedDescription, e.domain]];
225
-
226
- e = e.userInfo [NSUnderlyingErrorKey ];
234
+ return [NSString stringWithFormat: @" %@ (%@ )" , self .localizedDescription, self .domain];
227
235
}
228
-
229
- return result;
230
236
}
231
237
232
238
- (NSError *)mmm_underlyingError {
0 commit comments