Need help with crash report

Hi,


This is my code:

  do{

  let options: [NSAttributedString.DocumentReadingOptionKey: Any] = [
  NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html,
  NSAttributedString.DocumentReadingOptionKey.characterEncoding: String.Encoding.utf8.rawValue]


  let string = try NSMutableAttributedString(data: data, options: options, documentAttributes: nil)

  let attributes: [NSAttributedString.Key: Any] = [.font : labelFont, .foregroundColor : textColor]
  string.addAttributes(attributes, range: NSRange(location: 0, length: string.length))

  return string
  }catch{
  return NSAttributedString()
  }


This is the crash report I got. I believe the problem originates with the creation of the NSMutableAttributedString on line 8 above.


Last Exception Backtrace:
0   CoreFoundation                 0x1d2608ec4 __exceptionPreprocess + 228 (NSException.m:172)
1   libobjc.A.dylib               0x1d17d9a40 objc_exception_throw + 56 (objc-exception.mm:557)
2   CoreFoundation                 0x1d251eb3c +[NSException raise:format:arguments:] + 104 (NSException.m:136)
3   Foundation                     0x1d305b980 -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 88 (NSException.m:165)
4   UIKitCore                     0x1ff7d081c _prepareForCAFlush + 632 (UIApplication.m:2663)
5   UIKitCore                     0x1ff7ff8d0 _beforeCACommitHandler + 20 (UIApplication.m:2764)
6   CoreFoundation                 0x1d25987cc __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32 (CFRunLoop.c:1822)
7   CoreFoundation                 0x1d2593460 __CFRunLoopDoObservers + 412 (CFRunLoop.c:1932)
8   CoreFoundation                 0x1d2593210 CFRunLoopRunSpecific + 468 (CFRunLoop.c:3249)
9   UIFoundation                   0x1dcc1f368 -[NSHTMLReader _loadUsingWebKit] + 1728 (NSHTMLReader.m:2562)
10  UIFoundation                   0x1dcc2233c -[NSHTMLReader attributedString] + 28 (NSHTMLReader.m:3139)
11  UIFoundation                   0x1dcc6f3ec _NSReadAttributedStringFromURLOrData + 8120 (NSAttributedStringAdditions.m:2405)
12  UIFoundation                   0x1dcc22278 -[NSAttributedString(NSAttributedStringUIFoundationAdditions) initWitData:options:documentAttrib... + 136 (NSAttributedStringAdditions.m:1385)
13  LifeCoach                     0x104370ca8 specialized @nonobjc NSMutableAttributedString.init(data:options: (<compiler-generated>:0)
14  LifeCoach                     0x104370ff0 specialized String.convertHtml(labelFont:textColor:stripLinks:) + 704 (<compiler-generated>:0)

I am not sure what could have caused this problem, or why the execption wasn't simply caught by my exception handler.


Frank

Replies

Could you insert some prints to isolate the problem ? At lines 2 and 6 and 9.


How is data defined at line 8 ?

Unfortunately I'm not even able to reproduce the problem on my computer yet. The crash report is from the app store.

Do you read data from html ? Can you look at the html content ?


Could it be those data are corrupted?

Or have you deallocated an object__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION seems to tell.


May have a look here:

https://stackoverflow.com/questions/40056303/ios-app-crashing-with-cfrunloop-is-calling-out-to-an-observer-callback-function

Well, all the possible data that could hit this function comes from my database. I just wrote a test that passed all of it through the function in a loop to see which one made it crash, and none of them did.

And yet, the crash appears 5 different times just from a small handful of Test Flight users testing it for only a couple of days.

all the possible data that could hit this function comes from my database


What sort of data do you store in the database? User editable? Take from some web sites? Or all pre-defined?

Passing some limited number of tests has no meaning here in your case.

why the execption wasn't simply caught by my exception handler.

I can explain that part. Your app has crashed due to an unhandled language exception, as used by the exception handling infrastructure for Objective-C [1]. Swift’s error handling uses a different mechanism, one that acts more like a nice wrapper around Cocoa’s

NSError
. Swift is not able to handle Objective-C exceptions, and thus an exception through by Objective-C code in the frameworks will not be caused by your Swift error handler.

You can learn more about this in the Error Handling section of the The Swift Programming Language. And if you’re interested in the historical context for this, check out:

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

[1] That’s also shared with C++.

With regards your crashing problem, please post the full symbolicated Apple crash report. It’s hard to say for sure what’s going on here without seeing more of the context.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"