-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
Fix: don't crash app when applicationContext
is not available
#217
Conversation
applicationContext
is not availableapplicationContext
is not available
|
||
val context = applicationContext ?: run { | ||
// TODO: add logging later | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tbh, I am a bit hesitant with this approach, because if someone removes our SentryContextProvider
for whatever reason (as mentioned here for example), the SDK init will silently fail and the users wont be aware of that. Perhaps there's a better way to handle ProcessPhoenix specifically?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the problem that ContentProviders are not loaded at all, or that context
or context.applicationContext
is null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've set up some debug logs and the application init is triggered twice and during the the content provider is not loaded before so applicationContext crashes due to lateinit
but on the second load it works fine because the content provider has already set the context:
Rebirth triggered now (click button that runs rebirth)
Try init sentry android: app context null (app tries to restart process, content provider is not triggered before)
Content provider loaded (now content provider is triggered)
Try init sentry android: app context sample.kmp.app.android.SentryApplication@d0c4ab0 (now we have access to app context)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I see, I guess there's no many ways around it anyway. After we implement logging that should help also 👍
📜 Description
lateinit
crashes the application if not set for example when using the Phoenix libraryWhen calling
ProcessPhoenix.triggerRebirth(context)
the app is actually restarted twice and only one the second time the content providers are loaded.💡 Motivation and Context
Fixes #212
💚 How did you test it?
Manual,
SentryContextProviderTest
📝 Checklist
You have to check all boxes before merging:
sendDefaultPII
is enabled.🔮 Next steps