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

Mac app crashes on launch when using Sentry static framework #3949

Closed
bjhomer opened this issue May 7, 2024 · 4 comments · Fixed by #3957
Closed

Mac app crashes on launch when using Sentry static framework #3949

bjhomer opened this issue May 7, 2024 · 4 comments · Fixed by #3957

Comments

@bjhomer
Copy link
Contributor

bjhomer commented May 7, 2024

Platform

macOS

Environment

Production, Develop, TestFlight

Installed

Swift Package Manager

Version

8.25.0

Did it work on previous versions?

8.21.0

Steps to Reproduce

  1. Create a new macOS app
  2. Add Sentry as an SPM dependency
  3. Change the Principal Class to SentryCrashExceptionApplication, as described here.
  4. Run the app

See the attached sample project, which should reproduce the issue.

Expected Result

The app should launch when run.

Actual Result

The app crashes on launch. Nothing appears in the Xcode console, but in the macOS console, we see this:

Unable to find class: SentryCrashExceptionApplication, exiting

I suspect that because there is no reference to SentryCrashExceptionApplication in the code, the class was never linked in from the static library, and thus is not present at runtime. If I add any reference to SentryCrashExceptionApplication in the code, it launches correctly. For example, I can add this:

let x = SentryCrashExceptionApplication.self
print(x)

Note, though, that if this reference were optimized out by the compiler, then the app might crash again. (Hence the need to actually print it.)

It would be nice if Sentry itself could reference SentryCrashExceptionApplication on macOS, so that it is seen as a transitive dependency and thus would be linked in when other Sentry APIs are referenced. Alternatively, if referencing SentryCrashExceptionApplication in code is necessary, this should be documented.

Are you willing to submit a PR?

I'd be willing to, but it's not clear what route the team wants to take

@bjhomer
Copy link
Contributor Author

bjhomer commented May 7, 2024

Sample project that reproduces the issue:
SentryMacCrash.zip

@brustolin
Copy link
Contributor

Hello @bjhomer, this happens because the compiler is stripping the lib from unused code.
You can solve this by adding a reference to SentryCrashExceptionApplication somewhere in your code just like this:

_ = SentryCrashExceptionApplication.shared

@bjhomer
Copy link
Contributor Author

bjhomer commented May 7, 2024

Right, and I noted that in my ticket. This should perhaps be documented, though, as right now, following the instructions leads to an app that won't launch.

@brustolin
Copy link
Contributor

brustolin commented May 8, 2024

Thanks for the feedback, we will implement your suggestion of having the reference inside Sentry SDK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants