Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crash report indicating crash on line 0?

Can anyone help demystify this crash report?

There's no exception name or reason, and the backtrace shows the crash happening on line 0 of the file that contains the init method that crashed. What?

Incident Identifier: TODO
CrashReporter Key:   TODO
Hardware Model:      iPhone7,2
Process:         AppName [1112]
Path:            /private/var/mobile/Containers/Bundle/Application/2632C5D7-6A07-4002-A27B-D547E9A7345C/AppName.app/AppName
Identifier:      com.app.name
Version:         67
Code Type:       ARM-64
Parent Process:  launchd [1]

Date/Time:       2015-06-26 18:20:18 +0000
OS Version:      iPhone OS 8.3 (12F70)
Report Version:  104

Exception Type:  SIGTRAP
Exception Codes: TRAP_BRKPT at 0x10008c370
Crashed Thread:  0

Application Specific Information:
*** Terminating app due to uncaught exception '', reason: ''

The first couple symbolicated lines of the crashed thread:

0    AppName 0x000000010008c370 init (article, $metatype) (ArticleImageProvider.swift:0)
1    AppName 0x000000010006b0c4 shareArticleActivityViewController (article, track) (BasicArticleSharingController.swift:28)
2    AppName 0x0000000100063198 sharePressed () (DetailsViewController.swift:202)
3    AppName 0x00000001000600c8 sharePressed () (DetailsViewController.swift:200)
4    AppName 0x00000001000bfa8c sharePressed () (ContentNavView.swift:108)
5    AppName 0x000000010022f4b4 __55-[ASControlNode sendActionsForControlEvents:withEvent:]_block_invoke (ASControlNode.m:360)
6    AppName 0x000000010022f21c -[ASControlNode sendActionsForControlEvents:withEvent:] (ASControlNode.m:381)
7    AppName 0x000000010022e5b8 -[ASControlNode touchesEnded:withEvent:] (ASControlNode.m:191)
8    AppName 0x000000010026185c -[_ASDisplayView touchesEnded:withEvent:] (_ASDisplayView.mm:173)
9    UIKit 0x0000000187613d8c forwardTouchMethod + 260
10    UIKit 0x00000001874b0a2c -[UIWindow _sendTouchesForEvent:] + 696
11    UIKit 0x00000001874a9f68 -[UIWindow sendEvent:] + 680
12    UIKit 0x000000018747d18c -[UIApplication sendEvent:] + 260
13    UIKit 0x000000018771e324 _UIApplicationHandleEventFromQueueEvent + 15420
14    UIKit 0x000000018747b6a0 _UIApplicationHandleEventQueue + 1712

Here's some code:

// Where I attach the action to my button in ContentNavView
    shareButton.addTarget(self, action: "sharePressed", forControlEvents: ASControlNodeEvent.TouchUpInside)

/* snip */

// The implementation of ContentNavView#sharePressed()
func sharePressed() {
    delegate.sharePressed()
}


// The implementation of DetailsViewController#sharePressed()
func sharePressed() {
    if let cell = currentCell {
        let activityViewController = BasicArticleSharingController.shareArticleActivityViewController(cell.article)

        self.view.window?.rootViewController?.presentViewController(activityViewController, animated: true, completion: nil)
    }
}


// The implementation of BasicArticleSharingController#shareArticleActivityViewController(::) up to the initializer
class func shareArticleActivityViewController(article: Article, track: Bool = true) -> UIActivityViewController {
    var article = CoreDataManager.sharedManager.managedObjectContextForCurrentThread().objectWithID(article.objectID) as! Article

    let activities = [
        ArticleImageProvider(article: article), // Crash when calling this init?
        ArticleLinkProvider(article: article)
    ]

    /* snip */
}


// Implementation of the init that's crashing.  Apparently Swift only reports the class that crashes, not the line that crashes, so here's the implementation that I thought wasn't relevant.
final public class ArticleImageProvider: UIActivityItemProvider {

    let articleObjectID: NSManagedObjectID

    init(article: Article) {
        self.articleObjectID = article.objectID

        let article: Article = CoreDataManager.sharedManager.managedObjectContextForCurrentThread().objectWithID(article.objectID) as! Article

        let thumbnailCut = article.headlineImage?.cutWithShape(.Landscape)

        if let path = thumbnailCut?.localURL?.path {
            if let image = UIImage(contentsOfFile: path) {
                super.init(placeholderItem: image)
            }
            else {
                super.init(placeholderItem: UIImage())
            }
        } else {
            super.init(placeholderItem: UIImage())
        }
    }

    /* snip */
}
like image 367
Hyperbole Avatar asked Jul 10 '15 19:07

Hyperbole


1 Answers

So, a few things I learned here:

  1. objectWithID: returns NSManagedObject. That's it. There's no guarantee that the object you're sending that message to will return an object of the same type as the receiver, so testing the returned object is the safest way to handle this. As a corollary to that, scoping NSFetchRequests to reduce or eliminate threading issues with managed objects is a paramount concern and will eliminate this problem altogether.
  2. There are simply fewer signal traps in compiled Swift code, so getting a crash report from Apple or Crittercism (through NSThread#callStackSymbols or some other API) will always return the same junk I'm showing here. The best you can do is infer the lexical scope that's likely the cause of the crash and comb the code for any possible errors. We're stuck having to do this until Swift matures.
  3. Use implicitly unwrapped optionals sparingly.
like image 75
Hyperbole Avatar answered Sep 29 '22 13:09

Hyperbole