fix: prevent native crash when a transformer worklet throws#14
Merged
Conversation
RunTransformer called the transformer through runSync and used the result unconditionally. In release builds runSync is a raw jsi Function::call, so an error thrown by the worklet propagated as jsi::JSError through the UIKit text input delegate / Android TextWatcher and aborted the app. In debug builds the worklets call guard reports the error to LogBox and returns undefined, so the following asObject call threw with the same result. Catch jsi errors around the transformer invocation and result extraction, log them to the UI runtime console, and fall back to leaving the input untransformed. Add a throwing transformer card to the example app to exercise the path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
A transformer worklet that throws kills the app natively: the error propagates uncaught from
RunTransformerinto the iOStextInputDidChangedelegate / Android JNI TextWatcher and aborts with SIGABRT on the first keystroke. In release builds worklets'runSynccalls the function raw (source); in debug the call guard returnsundefinedand the followingasObject()throws instead. This is easy to hit from user code — any transformer returning an out-of-bounds selection makesvalidateSelectionthrow by design.Solution
Never let a transformer error cross the native boundary, and surface it instead of swallowing it. The worklet call and result extraction are wrapped in try/catch; caught errors are logged (LogBox via the worklets call guard in debug,
console.erroron the UI runtime in release) andRunTransformerreturnsstd::nullopt, which both platforms already treat as "no transform" — the input keeps the raw text.The example app has a new "Throwing Transformer" card that exercises the path.
Test plan
Verified on-device with the new example card (every keystroke throws):
RunTransformer→textInputDidChange). After: app stays alive, LogBox shows the error, input keeps the raw text.JSErrorcatch directly): typed 5 characters; app survived and the syslog shows five[rntti] Transformer threw an error: …entries with the value growing 1→5.