fix: prevent crashes during onuncaughterror #141
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR aims to address some unwanted crashes that would happen during the
OnUncaughtError
handler.The first relates to how the
AppPackageJson
file was being read to fetch thediscardUncaughtJsExceptions
flag. The NSJSONSerialization would produce a NSDictionary that would get autoreleased. On subsequent calls toOnUncaughtError
, theAppPackageJson
pointer would be cleared causing a bad access.To address this, I alloc and init a new NSDictionary from the serialization so that this dictionary will not get released between calls to
OnUncaughtError
. I'm not super familiar with Objective-C or how this runtime is setup, so I don't know if there is a point where we should manually release this dictionary. Please let me know if this should be handled.Second, I ran into an unhelpful stack trace when trying to test the error events I setup and eventually realized that my event handlers were also causing a javascript exception, but since we were already in the
OnUncaughtError
method, thetns::Assert
would be false and quit the app. I addressed this by usingTryCatch
and logging the caught error so developers have visibility on if their error event handlers are also causing an error.This PR will most likely close #126 and possibly is related to some crashes other users have reported.