Skip to content

crashedLastRun returns unreliable and unexpected values and shows undocumented behavior #4958

@wiedem

Description

@wiedem

Platform

iOS

Environment

Production

Installed

Swift Package Manager

Version

8.46.0

Xcode Version

16.2

Did it work on previous versions?

No response

Steps to Reproduce

The way in which it is currently possible to determine whether an application has crashed in the last session has a design flaw that makes it impossible to reliably determine whether an application has not crashed.

Consider the following simple example to reproduce the issue:

NSLog("### [1] Crashed last run: \(SentrySDK.crashedLastRun)")

SentrySDK.start { options in
    NSLog("### [2] Crashed last run: \(SentrySDK.crashedLastRun)")
}

NSLog("### [3] Crashed last run: \(SentrySDK.crashedLastRun)")

The log outputs for [1], [2] and [3] will display false even if the app crashed in the last session.

Expected Result

crashedLastRun should not return false if it's currently unknown if the app did crash in the last session or not.
Returning false although the status is actually still unknown is at least unexpected and leads to the problem that you can never be sure in an app whether the app has actually not crashed in the last session.

An expected behavior would be that when attempting to retrieve crashedLastRun, although the status is currently still unknown, a value is returned that clearly signals this status, e.g. via a nil value or by returning an error.

In addition, the behaviour in this regard should also be documented, which it currently is not.

Now there is the onCrashedLastRun handler, which is called asynchronously as soon as the SDK knows that the app has crashed in the last session, but this method is not called if the app has not crashed.
In other words, there is no mechanism that signals the status as soon as the SDK knows that the app has not crashed in the last session.

A possible solution would be if onCrashedLastRun is also called at the moment when the SDK knows the actual status and passes this status via a parameter. However, you should probably then rename the handler method to avoid confusion.

Actual Result

  1. SentrySDK.crashedLastRun always returns false before the SentrySDK.start method has been called, no matter if the app did crash in the last session or not.
  2. SentrySDK.crashedLastRun always returns false in the options closure of the SentrySDK.start method, no matter if the app did crash in the last session or not.
  3. SentrySDK.crashedLastRun may return false after the SentrySDK.start call even if the app did crash in the last session since the start method is an asynchronous process.

Are you willing to submit a PR?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    Needs Investigation

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions