Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting error on loading pending reports #149

Closed
1 task
hemaks123 opened this issue Oct 30, 2020 · 14 comments
Closed
1 task

Getting error on loading pending reports #149

hemaks123 opened this issue Oct 30, 2020 · 14 comments
Labels

Comments

@hemaks123
Copy link

Description

I am getting, "The file “live_report.plcrash” couldn’t be opened because there is no such file." error when trying load the pending reports.

Repro Steps

Please list the steps used to reproduce your issue.

  1. Tried to simulate a crash in SwiftUI view, the crash happened for array out of bounds
  2. When tried to call the loadPendingReportWithErrors, throws the above error.

Sample code I tried is given below,
On AppLaunch calling's below method -
private func setUpCrashReporter() {
//Crash report Activate
do {
try crashReporter?.enableAndReturnError()
debugPrint("crash report is active")
} catch let error {

    }
    if ((crashReporter?.hasPendingCrashReport()) != nil) {
        self.handleCrashReport()
    }

// if CrashReporter.Shared.crashReportActivate() == true {
// //Crash repoprt is Active
// debugPrint("crash report is active")
// }

    if CrashReporter.Shared.handleCrashReport() == true {
        //crash report can handle the crash
        debugPrint("crash report is handled")
    }
    CrashReporter.Shared.crashReportActivate()
}

func handleCrashReport() -> Bool {
    let data:Data?
    
    guard let crashReporter = PLCrashReporter.shared() else {return false}
    
    do {
        data = try crashReporter.loadPendingCrashReportDataAndReturnError()
        if data != nil { //crashReporter.hasPendingCrashReport()
            let report = try PLCrashReport(data: data!)
            if let formettedCrashReport = PLCrashReportTextFormatter.stringValue(for: report, with: crashTextFormat) {
              
                var identifier:String
                if let UID = report.uuidRef {
                     identifier = "\(UID.hashValue)"
                }else {
                    identifier = UUID().uuidString
                }
                crashReporter.purgePendingCrashReport()
                return true
          }
        }
        
    } catch {
        return false
    }
   return false
}

Details

  1. Which SDK version are you using?
  2. Which OS version did you experience the issue on? - iOS 14
  3. Which CocoaPods/Carthage/Xcode version are you using? - Xcode -12
  4. What device version did you see this error on? Were you using an emulator or a physical device? - In simulator I tried
  5. What language are you using?
    • Swift
  6. What third party libraries are you using? - CrashReporter
@AnastasiaKubova
Copy link
Contributor

Hi! Thanks for getting in touch with us!
I try to reproduce your issue follow your steps, but unfortunately I didn't get the same behavior.
Could you please share a sample project with reproducing this issue?

@krassx
Copy link

krassx commented Oct 30, 2020

Can't check the code at the moment, so the following is just a guess. If I am not missing anything, the line

if ((crashReporter?.hasPendingCrashReport()) != nil) {

may incorrectly be truthy when false is returned from hasPendingCrashReport (which is defined as BOOL). And, consequently, the code will call the handleCrashReport() method, when it should not.

@hemaks123
Copy link
Author

CrashReporterSample.zip

@hemaks123
Copy link
Author

Please check the sample code where I simulated a crash already but Loading data throws the error.

@hemaks123
Copy link
Author

try crashReporter.loadPendingCrashReportDataAndReturnError() this returns "The file “live_report.plcrash” couldn’t be opened because there is no such file." error.

@hemaks123
Copy link
Author

Could you please tell me, is there any dashboard where I could see the crash reports? How long it will take to return the pending reports, is there any particular duration? Because I just need to see the logs when crash happens. If you can share any documentation for this also would be great.

@DmitriyKirakosyan
Copy link
Contributor

Hi @hemaks123 , thank you for the demo app. I've checked it and found a couple of issues in your code:

  • The check crashReporter.hasPendingCrashReport() is missing
    You should always check if hasPendingCrashReport returns true before calling loadPendingCrashReportDataAndReturnError. Otherwise you'll get the error no such file.
  • CrashReporter.Shared.crashReportActivate() is called twice (doesn't affect the functionality though)

Follow the steps to get the crash report data:

  • Launch the app (Important: The app should not be launched in Debug mode, otherwise XCode will catch and debug the error)
  • Click the button
  • Launch the app again, this time in Debug mode and observe that loadPendingCrashReportDataAndReturnError returns the crash report data.

Here is a demo application that you can use as an example of how to use the lib.

Please, let me know if it works for you.

Could you please tell me, is there any dashboard where I could see the crash reports? How long it will take to return the pending reports, is there any particular duration? Because I just need to see the logs when crash happens.

The PLCrashReporter library doesn't send data over the network, and doesn't provide dashboards or any other user interface for monitoring crashes. If you need a UI for tracking your crashes, you can use MS App Center or create your own tracker based on data from the PLCrashReporter.

@hemaks123
Copy link
Author

hemaks123 commented Nov 3, 2020

Hi DmitriyKirakosyan ,

I tried with the latest framework in Xcode 12 and tried your approach as well, it is working now. I really appreciate all of your help on this solution.
Do the framework track the Swift errors or runtime errors, MACH_EXCEPTION and the errors thrown by SwiftUI?
I can see only 1.7.2 . How can I get the latest 1.8.0 version release ?
eg : var arr = [String]
arr[1] // will crash out of range

@MatkovIvan
Copy link
Contributor

Do the framework track the Swift errors or runtime errors, MACH_EXCEPTION and the errors thrown by SwiftUI?

All not caught exceptions/errors falls to mach server or to just unix signal handler. PLCR should catch all of it.

I can see only 1.7.2 . How can I get the latest 1.8.0 version release ?

@hemaks123 1.8.0 is not release yet, it will be the next version. It's always available for building from sources if you want to test unreleased changes

@MatkovIvan
Copy link
Contributor

1.8.0 has been released. Good timing :)

@hemaks123
Copy link
Author

Good to hear that, I will try to integrate the latest release.

@hemaks123
Copy link
Author

@DmitriyKirakosyan :
I tried with the latest framework, and simulated the scenario by creating crash on release mode and then tried to check in debug mode. It is giving the report on next day, I am not able to get the report on next launch. Is there any duration for getting the crash reports or any sample code or API documentation. I need to send the last crash report to server on each relaunch.
My implementation is given below ,

  1. Added the Crashreporter 1.8.0 framework
  2. Added the simulated a crash on release mode.
  3. Relaunched it in debug mode
  4. Still hasPendingCrashReports returns false(I had simulated a crash)

@DmitriyKirakosyan
Copy link
Contributor

@hemaks123,

I've tested v1.8 with your project and it worked for me as expected. I've also tested on a new test app, adding the lib manually and downloading via cocoa pods, on an emulator and a real device. Everything worked as expected.

Could you please share more details about your test steps?
(Note that the crash logs are writing on the device's disk and the file is unique for each app. So you should initiate a crash and debug the crash report for the same app on the same device.)

Here's what I do:

  1. Opened your test project and updated the PLCrashReporter to v1.8
  2. Launched the app from Xcode with the debugger attached and stopped the debugging
  3. Launched the app on the device without debugging and clicked the button. The app crashed
  4. Launched the app from Xcode with the debugger attached. hasPendingCrashReports was true and I could load the crash report data using loadPendingCrashReportDataAndReturnError

Is there any duration for getting the crash reports or any sample code or API documentation.

Actually, you should not experience any delay in getting the crash report. It's writing to the file once the crash happens and thus it should be available on the next launch. If you don't get the crash report on the next app launch, let's figure out why it happens :) Please try my steps and let's see if it works for you.

The sample code can be found here: https://github.com/microsoft/plcrashreporter/blob/master/Other%20Sources/Crash%20Demo/main.m

@vvechkanov
Copy link
Contributor

Hello again!

We haven’t heard from you in a few days, hope everything is going well! We did not reproduce this issue, so I will close this ticket for now. Should you need further assistance or have any further questions, please feel free to reopen or/and reply.

Thanks for using App Center!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants