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

Remove ErrorHandler #4723

Merged
merged 2 commits into from
Jul 13, 2023
Merged

Remove ErrorHandler #4723

merged 2 commits into from
Jul 13, 2023

Conversation

tomekzaw
Copy link
Member

@tomekzaw tomekzaw commented Jul 12, 2023

Summary

Currently, ErrorHandler is referenced in 11 files and has 2 separate implementations (one for Android and one for iOS) but it turns out that since Reanimated v3 there's only 1 place where we use it:

} catch (std::invalid_argument e) {
errorHandler->setError("Failed to convert value to number");
errorHandler->raise();
}

This PR removes ErrorHandler completely from our codebase in favor of old simple throw std::runtime_error.

Test plan

Check if CI is green.

@tomekzaw tomekzaw requested a review from piaskowyk July 12, 2023 15:25
Copy link
Contributor

@tjzel tjzel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works on andrewid 🎬

@@ -530,8 +523,7 @@ void NativeProxy::setupLayoutAnimations() {
yogaValues.setProperty(rt, key, value);
}
} catch (std::invalid_argument e) {
errorHandler->setError("Failed to convert value to number");
errorHandler->raise();
throw std::runtime_error("Failed to convert value to number");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you tried to trigger this exception in application? I'm wondering if it crash app or just display RedBox with message.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out it's actually shown using RedBox! 😄

Zrzut ekranu 2023-07-12 o 22 29 43

@tomekzaw tomekzaw added this pull request to the merge queue Jul 13, 2023
Merged via the queue into main with commit 724d407 Jul 13, 2023
9 checks passed
@tomekzaw tomekzaw deleted the @tomekzaw/remove-error-handler branch July 13, 2023 07:46
Latropos pushed a commit that referenced this pull request Jul 13, 2023
<!-- Thanks for submitting a pull request! We appreciate you spending
the time to work on these changes. Please follow the template so that
the reviewers can easily understand what the code changes affect. -->

## Summary

Currently, `ErrorHandler` is referenced in 11 files and has 2 separate
implementations (one for Android and one for iOS) but it turns out that
since Reanimated v3 there's only 1 place where we use it:


https://github.com/software-mansion/react-native-reanimated/blob/ae2b9ded42ec03589e1fccd1ecc8ad3d967d67c2/android/src/main/cpp/NativeProxy.cpp#L532-L535

This PR removes `ErrorHandler` completely from our codebase in favor of
old simple `throw std::runtime_error`.

## Test plan

Check if CI is green.
github-merge-queue bot pushed a commit that referenced this pull request Aug 26, 2023
<!-- Thanks for submitting a pull request! We appreciate you spending
the time to work on these changes. Please follow the template so that
the reviewers can easily understand what the code changes affect. -->

## Summary

This PR implements and exposes a new API for creating worklet runtimes
as well as running and scheduling worklets both from JS and C++ code.
The motivation of this PR was to allow for easier integration of other
third-party libraries with Reanimated worklets.

The following changes were required but they were merged as separate PRs
for the ease of code review:

* #4608
* #4612
* #4621
* #4722
* #4723
* #4731
* #4765
* #4768
* #4773
* #4775
* #4779
* #4780
* #4785
* #4800
* #4869
* #4871
* #4929

## Changes

1. Removed `RuntimeManager` and `JSRuntimeHelper` in favor of
`WorkletRuntime` class
- `WorkletRuntime` is runtime-agnostic (supports JSC/Hermes/V8), has
built-in debugging support on Hermes (via Chrome DevTools Protocol), is
a `jsi::HostObject` so it can be passed between JS/C++, offers method
for calling worklets via callGuardDEV
- Refactored all usages of UI runtime in `NativeReanimatedModule`,
`AnimatedSensorModule`, `EventHandlerRegistry`
- Added `WorkletRuntimeRegistry` to keep track of whether worklet
runtime is still alive
- Added `WorkletRuntimeCollector` that is a host object that unregisters
worklet runtime in its destructor (i.e. when runtime is terminated)
- Added possibility to customize name of runtime created by
`ReanimatedRuntime::make` for debugging purposes
1. Added `createWorkletRuntime` function along with `runOnRuntime`,
`runOnRuntimeSync` and `backgroundTask`
    - Added `WorkletRuntimeExample.tsx` to test out the changes
1. Removed `RuntimeDecorator` class in favor of having separate classes
in order to decouple code
- Moved `RuntimeDecorator::decorateRuntime` to
`RNRuntimeDecorator::decorate` that injects JSI bindings specific for
React Native runtime (e.g. `_WORKLET_RUNTIME`)
- Moved `RuntimeDecorator::decorateUIRuntime` to
`UIRuntimeDecorator::decorate` that injects UI-specific JSI bindings
(e.g. `_updateProps`)
- Added `WorkletRuntimeDecorator::decorate` that injects
worklet-specific JSI bindings (e.g. `evalWithSourceMap` or
`_makeShareableClone`)
1. Removed `CoreFunction` class and
`NativeReanimatedModule::installCoreFunctions` method in favor of
passing `valueUnpacker` code as a string (this is possible because of
the empty closure) and installing `callGuardDEV` from a worklet
1. Refactored shareables so that they support other runtimes than only
RN and UI runtime
1. Refactored `NativeReanimatedModule` constructor and members
- Eliminated `LayoutAnimationsManager::setJSLogger` method in favor of
passing `JSLogger` in its constructor
    - Moved Paper- and Fabric- only fields to `#ifdef`s
- Added missing trailing underscores in member names for the purpose of
consistency
    - Added `const` keyword wherever possible
1. Moved `jsi::Scope` from `UIScheduler::scheduleOnUI` to
`NativeReanimatedModule::scheduleOnUI` in order to decouple
`RuntimeManager` and `UIScheduler` and also because some UI jobs may not
need runtime access

## Future plans
- Split C++ headers into public and private
- Create UI runtime using `createWorkletRuntime` from JS instead of from
C++
- Pass `valueUnpacker` code via argument of
`ReanimatedModule.installTurboModule` method of instead of calling
`NativeReanimatedModule.installValueUnpacker`
- Implement `createWorkletRuntime` on web?

## Test plan

💣
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants